I'm creating notifications in my Android application, and would like to have an option in my preferences to set what sound is used for the notification. I know that in the Settings application you can choose a default notification sound from a list. Where does that list come from, and is there a way for me to display the same list in my application?
5 Answers
Just copy/pasting some code from one of my apps that does what you are looking for.
This is in an onClick handler of a button labeled "set ringtone" or something similar:
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
this.startActivityForResult(intent, 5);
And this code captures the choice made by the user:
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (resultCode == Activity.RESULT_OK && requestCode == 5) {
Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (uri != null) {
this.chosenRingtone = uri.toString();
} else {
this.chosenRingtone = null;
}
}
}
Also, I advise my users to install the "Rings Extended" app from the Android Market. Then whenever this dialog is opened on their device, such as from my app or from the phone's settings menu, the user will have the additional choice of picking any of the mp3s stored on their device, not just the built in ringtones.

- 183,023
- 24
- 297
- 295
-
Thank you.I am able to display ringtone successfully using your code But in **onActivityResult()** method I am getting error "Cannot make a static reference to the non-static method getParcelableExtra(String) from the type Intent" at your line "Uri uri = Intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);" – Dharmendra Oct 20 '11 at 08:47
-
1That line should read "Uri uri = intent.getParcelableExtra...". Note the lowecase "i" in "intent". Just a typo on the above code. – zeh Dec 12 '11 at 21:13
-
Helpful code and mind the small letter in intent.getParcelableExtra... Thanks a lot – djk Feb 04 '12 at 06:19
-
4How should I get the name of the ringtone that was returned from the ringtonePicker intent ? – android developer Apr 04 '13 at 11:43
-
1small fix to remember last choosen: intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (chosenRingtone ==null) ? (Uri)null :Uri.parse(chosenRingtone)); – Alexander Sidikov Pfeif Jul 17 '14 at 12:45
-
Better put the "Select Tone" string in resources xml. – Niki Romagnoli Jul 27 '15 at 13:48
-
5To get the name of the Ringtone, do this: Ringtone ringtone = RingtoneManager.getRingtone(context, uri); String title = ringtone.getTitle(this); – Vineet Ashtekar Feb 23 '16 at 18:41
-
copied these two chunks of code exactly but I receive resultCode=0 regardless if user presses OK or Cancel – Kyle Sweet Aug 02 '16 at 13:11
-
My self-inflicted pain |^|^|^| was due to placing the code in an activity that was declared as singleInstance in the manifest – Kyle Sweet Aug 03 '16 at 03:35
-
Is there any way that at the time of displaying ring tone I can allow user to add some custom ringtone too programmatically? – Hammad Hassan Oct 02 '16 at 12:09
-
Can we call this default intent with some custom ringtones list? – Hammad Hassan Nov 06 '16 at 16:33
-
Is there any way to change the style of the Ringtone Picker Dialogue? I have a custom style and I would like to apply it in this ringtone picker. – Marcos Guimaraes Jan 10 '17 at 16:09
-
@androiddeveloper, You can get name by `Ringtone ringtone = RingtoneManager.getRingtone(this, uri); String title = ringtone.getTitle(this);` [https://stackoverflow.com/a/19187970/3525814] (post) – Kuvalya Mar 11 '18 at 20:17
-
@Kuvalya Thank you – android developer Mar 12 '18 at 11:57
-
The above code just brings up the dialog with ringtones **not with notification**! To show a list of notification sounds the following line needs to be add: `intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));` – YBrush Mar 26 '18 at 17:59
Or just stick this in your preferences XML:
<RingtonePreference android:showDefault="true"
android:key="Audio" android:title="Alarm Noise"
android:ringtoneType="notification" />
Full content of my sample XML just for context:
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference android:title="Some value"
android:key="someval"
android:summary="Please provide some value" />
<EditTextPreference android:title="Some other value"
android:key="someval2"
android:summary="Please provide some other value" />
<RingtonePreference android:showDefault="true"
android:key="Audio" android:title="Alarm Noise"
android:ringtoneType="notification" />
</PreferenceScreen>

- 750
- 4
- 15

- 3,005
- 2
- 26
- 37
This is the method I use to get a list of notification sounds available in the phone :)
public Map<String, String> getNotifications() {
RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();
Map<String, String> list = new HashMap<>();
while (cursor.moveToNext()) {
String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
list.put(notificationTitle, notificationUri);
}
return list;
}
EDIT: This is for the comment regarding how to set the sound in the NotificationCompat.Builder. This method instead gets the ringtone's ID which is what the phone uses, instead of the human readable TITLE the other method got. Combine the uri and the id, and you have the ringtones location.
public ArrayList<String> getNotificationSounds() {
RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();
ArrayList<String> list = new ArrayList<>();
while (cursor.moveToNext()) {
String id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
String uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
list.add(uri + "/" + id);
}
return list;
}
The above code will return a list of strings like "content://media/internal/audio/media/27".. you can then pass one of these strings as a Uri into the .setSound() like:
.setSound(Uri.parse("content://media/internal/audio/media/27"))
Hope that was clear enough :)

- 2,207
- 1
- 22
- 36
-
That's nice, but how do you set the sound to be played with NotificationCompat.Builder.setSound( uri )? Setting one of the Uri reading from the RingtoneManager does not work – infero May 04 '15 at 11:32
-
I've edited the post with the answer @infero , hope it's clear and solves your problem! – Murphybro2 May 05 '15 at 08:19
-
thanks for the update. I was trying setting the sound this way with the id before, but used an id that did not exist - :-( grrrr. Thanks again – infero May 05 '15 at 09:56
-
Is it possible to get the currently set notification sound by modifying the above code? – SoulRayder Oct 10 '16 at 07:13
-
@SoulRayder `Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION);` gives you the Uri of the current notification sound chosen by user in device settings, and `RingtoneManager.getRingtone(this, actualUri).getTitle(this)` gives you its title. – jk7 Apr 20 '18 at 21:35
-
@SportAtomDroid How so? This is some pretty old code, so that's interesting! – Murphybro2 Oct 08 '19 at 13:43
-
RingtonePreference does not work any more. As well android.intent.action.RINGTONE_PICKER – SportAtomDroid Oct 08 '19 at 13:51
public void listRingtones() {
RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
// manager.setType(RingtoneManager.TYPE_RINGTONE);//For Get System Ringtone
Cursor cursor = manager.getCursor();
while (cursor.moveToNext()) {
String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String uri = manager.getRingtoneUri(cursor.getPosition());
String ringtoneName= cursor.getString(cursor.getColumnIndex("title"));
Log.e("All Data", "getNotifications: "+ title+"-=---"+uri+"------"+ringtoneName);
// Do something with the title and the URI of ringtone
}
}

- 1,784
- 19
- 23
Here's another approach (in Kotlin), build from other answers in this question, that allows you to specify the name of the tone, and then play it:
fun playErrorTone(activity: Activity, context: Context, notificationName: String = "Betelgeuse") {
val notifications = getNotificationSounds(activity)
try {
val tone = notifications.getValue(notificationName)
val errorTone = RingtoneManager.getRingtone(context, Uri.parse(tone))
errorTone.play()
} catch (e: NoSuchElementException) {
try {
// If sound not found, default to first one in list
val errorTone = RingtoneManager.getRingtone(context, Uri.parse(notifications.values.first()))
errorTone.play()
} catch (e: NoSuchElementException) {
Timber.d("NO NOTIFICATION SOUNDS FOUND")
}
}
}
private fun getNotificationSounds(activity: Activity): HashMap<String, String> {
val manager = RingtoneManager(activity)
manager.setType(RingtoneManager.TYPE_NOTIFICATION)
val cursor = manager.cursor
val list = HashMap<String, String>()
while (cursor.moveToNext()) {
val id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX)
val uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX)
val title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX)
list.set(title, "$uri/$id")
}
return list
}
It can probably take some refactoring and optimization, but you should get the idea.

- 63
- 3

- 1,064
- 12
- 25