I'm saving a sound from my app to be used as a ringtone or a notification sound. Here's part of my code, taken from this page:
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, soundName);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
values.put(MediaStore.Audio.Media.ARTIST, "artist");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
this.getContentResolver().insert(uri, values);
My understanding is that the sound will be saved as well as a ringtone, a notification sound and an alarm, as the flags are all set to "true". At least on the emulator this does work but on the actual device, the sound only shows up in the ringtone list, and I have no idea why.
EDIT: I've tried to investigate further: removing the line with "IS_RINGTONE" won't change anything (in case only one flag can be used at a time), the sound doesn't show up in the list with the notification-sounds.
Any help is appreciated.
Kind regards, Select0r
I played around with the path to get this solved and here's the solution I came up with so far:
On the emulator the path doesn't matter, the sound will appear in the ringtone as well as the notification-list.
On the phone, the sound will show up the the ringtone list if the file is saved to /media/audio/ringtones
OR /media/audio/
but NOT as a notification.
If I use the path /media/audio/notifications
the sound finally appears in the notification-list (!) but NOT in the ringtones any more.
So it seems I have to save the sound twice to get it into both list? (But why does saving it once work on the emulator?)
If there's another way of getting sounds into both lists (or even three lists, there are alarm tones as well, I just didn't bother playing around with them) with only saving them once, please let me know. (Right now my workaround is a dialog to let the user choose whether to save the sound as a ringtone or a notification.)