Note that there are some explanatory texts on larger screens.

plurals
  1. POMove Raw file to SD card in Android
    primarykey
    data
    text
    <p>I have a method that will <code>copy an Audio file from raw folder to SD card</code>. It takes two inputs</p> <ul> <li>ressound: .ogg Audio Raw file id.</li> <li>fName: the file name of the raw file in the SD card.</li> </ul> <p><strong>Updated</strong></p> <pre><code> public boolean saveas(int ressound, String fName){ byte[] buffer=null; InputStream fIn = getBaseContext().getResources().openRawResource(ressound); int size=0; try { size = fIn.available(); buffer = new byte[size]; fIn.read(buffer); fIn.close(); } catch (IOException e) { // TODO Auto-generated catch block return false; } String path="/sdcard/music/[my_package_name]/"; String filename=fName+".ogg"; String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath(); String completePath = baseDir + File.separator + "music" + File.separator + "my_package" + File.separator + filename; boolean exists = (new File(completePath)).exists(); if (!exists){new File(completePath).mkdirs();} FileOutputStream save; try { save = new FileOutputStream(completePath); save.write(buffer); save.flush(); save.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block return false; } catch (IOException e) { // TODO Auto-generated catch block return false; } sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename))); File k = new File(path, filename); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, "exampletitle"); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg"); values.put(MediaStore.Audio.Media.ARTIST, "cssounds "); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true); values.put(MediaStore.Audio.Media.IS_ALARM, true); values.put(MediaStore.Audio.Media.IS_MUSIC, true); //Insert it into the database this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values); return true; } </code></pre> <p>If the method returns true, Then the file is saved correctly to SD card. If it returns false, then there is an error. In my case, The method returns false when it enters the <code>FileNotFoundException</code> block. I can't find why !! everything seems fine to me.</p> <p>In case you ask me if I add the WRITE permission, I added it to the application tag in the Manifest file:</p> <pre><code> &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; </code></pre> <p>Any help please ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload