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. Error dan kadang hang @ k9

Rekans ...

Saat ini saya mencoba menggunakan aplikasi k9 versi terakhir utk mail
messaging. tetapi sering sekali muncul huruf ascii jika mereply email dari
sender, juga kadang hang minta di force to close. Kira 2x knp yaa ? Saat ini
os masih pakai android 1.5. di samsung galaxy spica.

salam Brian

sent by cupcake android 1
.5 spica

"Indonesian Android Community [id-android]" 

2. Question About Handler

Hi all,

I am trying to make a basic game.

I want to call the update() function every few seconds. So I found that it
can be done using Handler.

Whenever my handler receives a message, i will execute the update()

However, when I try adding User Inputs, it gets more complicated.

Under the onKeyDown() function, I send another message to the handler to
call the updateInput() function.

The problem is that when i continue clicking the key, update() function is
never called. I believe that is because onKeyDown() keeps sending the
message to the handler.

Can any one let me know how to solve this problem?

Thanks in advance.


3. Calling it quits for awhile..

4. pengguna Hero based on official 2.1 2.9 kernel!!

5. no ringtones show at Phone ringtones list

6. Weird Thing with my posts

7. Messaging Service Helpful?