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();
mediaPlayer.setDataSource(filename);
mediaPlayer.prepare();
int duration = mediaPlayer.getDuration();

File file = new File(filename);

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, filename);
values.put(MediaStore.MediaColumns.TITLE,
ringtoneNameTextView.getText().toString());
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);

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to