I want the user to be able to choose a notification sound for my app so I use the code below:
Intent ringtoneIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
ringtoneIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
ringtoneIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
ringtoneIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
ringtoneIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Choose");
ringtoneIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
fragment.startActivityForResult(ringtoneIntent, REQUEST_RINGTONE);
Unfortunately, my app's own notification sound isn't in the list. Google Hangouts, Calendar, and Facebook are in the list. I assume these programs have done something to register with android, but I cannot find any documentation on how to do this.
First copy your file to the rigntones folder (See Environment.DIRECTORY_RINGTONES)
Then register the sound:
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, nameOfSound);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, yourAppName);
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(file.getAbsolutePath());
getContentResolver().insert(uri, values);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With