How to get Ringtone name in Android?

stacksonstacks picture stacksonstacks · Oct 4, 2013 · Viewed 11k times · Source

I'm allowing my user to pick a ringtone for notifications in my app. I want to store the URI of the sound along with the human readable title of the sound.

So far the URI code works great:

Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

But when I try to get the title, and set it as a button text, I don't get anything. Seems to have no title?

String title = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_TITLE);
button.setText(title);

But my button text is empty. If I do:

button.setText(uri.toString());

then I see the uri perfectly. Should I just try to get the title from the URI? Thanks

Answer

Erik Nedwidek picture Erik Nedwidek · Oct 4, 2013

This should get it:

Ringtone ringtone = RingtoneManager.getRingtone(this, uri);
String title = ringtone.getTitle(this);

Refer to http://developer.android.com/reference/android/media/Ringtone.html for the documentation, but the short story: Ringtone.getTitle(Context ctx);