Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Ringtone name in Android?

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

like image 354
stacksonstacks Avatar asked Oct 04 '13 18:10

stacksonstacks


People also ask

What is meant by contact ringtone?

Giving custom and unique ringtones to your contacts can help you know the person calling you without picking the phone. The process is also pretty simple for both platforms (Android and iOS). You just need to follow the steps completely and your next call will sound with a new ringtone.


2 Answers

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);

like image 67
Erik Nedwidek Avatar answered Oct 18 '22 22:10

Erik Nedwidek


I personally had a serious performance problem when I tried the accepted answer, it took about 2 seconds to just load a list of 30 ringtones. I changed it a bit and it works about 10x faster:

uri = ringtoneMgr.getRingtoneUri(cursor.getPosition());
ContentResolver cr = getContext().getContentResolver();
String[] projection = {MediaStore.MediaColumns.TITLE};
String title;
Cursor cur = cr.query(uri, projection, null, null, null);
    if (cur != null) {
        if (cur.moveToFirst()) {
            title = cur.getString(0);
            cur.close();
like image 40
ulmaxy Avatar answered Oct 18 '22 22:10

ulmaxy