Ringtones saved from audio files in SD card disappear after reboot

by Nolan Lawson » Mon, 24 May 2010 06:35:49 GMT

Sponsored Links
 I'm having a problem creating ringtones from files saved to the SD
card.  I have succeeded in getting the information to be written to
the MediaStore database, and the files do show up in Settings -> Sound
& Display -> Phone ringtone.  However, as soon as I reboot the phone,
the files disappear from the list of ringtones.

The only clue I have is that the database in /data/data/
com.android.providers.media/databases/external-<guid>.db is getting
its rows deleted on startup.  The files themselves are not changing.
Even stranger is that, if I simply copy the file from the SD card to
the files/ directory of the internal storage directory for my app, and
then save THAT file as the ringtone, it works!  However, it doesn't
really seem feasible to me to force the user to keep two copies of the
audio file.

I do have a .nomedia file in the audio files directory (to avoid the
files showing up in the Music app), but I have tested this with and
without the .nomedia file and the same problem occurs.

Below is my code for creating the ringtone/notification.  Any
suggestions for fixing this bug?  The users of my app would be really
grateful if I figured this out.  Thanks!!

MediaPlayer mediaPlayer = new MediaPlayer();
int duration = mediaPlayer.getDuration();

File file = new File(filename);

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, filename);
values.put(MediaStore.MediaColumns.SIZE, file.length());
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
values.put(MediaStore.Audio.Media.ARTIST, "Artist Name");
values.put(MediaStore.Audio.Media.DURATION, duration);
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

newUri = getContentResolver().insert(uri, values);


Ringtones saved from audio files in SD card disappear after reboot

by Nolan Lawson » Mon, 24 May 2010 10:37:52 GMT

 ll right, I seem to have accidentally figured this out.  Hopefully my
explanation can help others having similar problems.

The problem seems to be not with the .nomedia file or with the
parameters in the ContentValues (my first guesses), but rather with
the names of the directories. Apparently, when you save ringtones or
notifications to the SD card, you HAVE to put them in a directory
called "ringtones" or "notifications." It doesn't seem to matter what
the parent directory is called (e.g. "/sdcard/foo/ringtones"), but the
names of the bottom-level directories have some special significance.

For instance, if you save an audio file to /sdcard/ringtones, and
insert it into the MediaStore with IS_NOTIFICATION and IS_RINGTONE
both set to true, the file will be visible as both a ringtone and a
notification - at least until you reboot. Once you reboot, Android
will overwrite those values and set everything to false except for
IS_RINGTONE, so it will no longer show up as a notification. Likewise
for /sdcard/notifications, except that it will set everything to false

So this means you apparently can't have an audio file that is both a
ringtone and a notification - if you want it to survive a reboot,

And if you save the file to some other directory name (e.g. /sdcard/
foo), then on reboot Android will just delete the row from the
"audio_meta" table entirely, and the files will not show up as either
a ringtone or a notification (which is what was happening to me). Or,
if you don't have a .nomedia file in that folder, it might try to
reinterpret it as a IS_MUSIC audio file, meaning it will show up in
the Music app.

Also, Android will rename the title of the ringtone to be whatever the
filename is minus the filetype suffix. So I have to save the file as
the MediaStore.MediaColumns.TITLE value plus ".ogg", or else Android
will just rename it for me after a reboot.

I'm glad that I found a solution, but this feels really hacky. Is
there a better way to do this? Also, does anyone know where the
documentation is for "ringtones" and "notifications" being keywords
for folder names? I looked in both RingtoneManager and MediaStore,
but couldn't find any mention of it.

Also, I've only tested this on a Nexus One running Eclair, so I'm not
sure if other phones or Android versions show the same behavior.

On May 23, 3:35pm, Nolan Lawson <nolan.law...@gmail.com> wrote:

Sponsored Links

Other Threads

1. TabActivity and startAcitivtyForResult

can make the TabActivity start it's childs activities for result?

I need it because I can't make result code from a tab to propagate all
the way up in the chain (it's reset in the TabActivity)



2. share root cliq

akhirnya cliq ane berhasil root nih #terharu...
terima awal sudah 1.3.18 ga bisa root pasrah deh. soalnya meskipun ga root enak 
juga, jadi ga terlalu dipkiri. 
begitu ada berita critical update langsung update wong toh ga bisa di root. 
alhasil jalan deh di 1.4.8
kemaren cek modmymoto eh ternyata sudah bisa root di 1.3.18 sama di 1.4.8
abis semalen donlot file yang dibutuhkan, tadi pagi root, sekarang coba posting 
mantab, lebih responsif, touchscreen daerah pinggir yang biasa macet sekarang 
sip dah. yang punya cliq jangan takut root hajar saja :p

Connected by rooted MOTOBLUR

"Indonesian Android Community [id-android]" 

3. Unable to set up email application on emulator for android 1.6

4. Eclipse + cupcake + other android projects in build path = VerifyError

5. setelah upgrade ke JD1

6. OOT: Mau Nexusone gratis?

7. Problems with mipmaps + non-square textures on MSM7200?