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. application in Long press Home button(Recent task info)

i am trying to start an activity from Receiver......
with listening to phone state change...but i am having an issue with
it....when activity started from reciever and finished after operation
performed my application comes in running tasks...which i dont want ...

can anybody help in this issue that activity can start and finish after
certain action performed but application should not come in long press home
button screen..


 A N K ! T......


2. Image Resizing and rescaling from code

Hi Friends,
i have two images, first image of size 345x 465 and second of 495x321.
so when i m using the first image in image view or layout, the image
is best fitted with screen whereas when i am using second image then
its not taking the full height of the phone or emulator and making
data /text to compress or collapse so the user cant view it properly.

is there any way so i can modify the second image to the SIZE of first
image, means i want to modify my image such that the HEIGHT should be
greater than the WIDTH so i can use it properly....need some solution
pls reply...


3. Android Low Memory Killer

4. How to create a temporary file

5. Detecting whether an APK is installed on the system folder

6. STLport problem

7. [WTShare] CyanogenMod's New Lockscreen