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. BroadcastReceiver not recei ving an alarm鈥檚 broadcast

Ok, I found the problem, hope this thread helps somebody else with the
same stupid errors:

My <receiver> was inside the <manifest> but outside the <application>
tags :-/


2. mini2440 Android bring-up instructions including files

similar wiki: to start android from scratch..

On Sat, Mar 27, 2010 at 7:10 AM, Shannon Haworth

> website: 

3. Input question.

4. Application not installed on Hero

5. A new site to open blocked sites, and forbidden

6. android.location.Location.distanceTo algorithm

7. CFP: droidcon 2010 - Business and Development in the Android Ecosystem (deadline 9 april 2010)