Muhammed Refaat
Muhammed Refaat

Reputation: 9103

How to get Ringtone from system sounds

I'm using AlarmManager to display alarms in my android app, I want to display a sound from the system available sounds as an alarm but the only availability for me is to choose between the already set sounds like ringtone, alarm, notification :

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); // OR TYPE_RINGTONE OR TYPE_NOTIFICATION
Ringtone r = RingtoneManager.getRingtone(mContext, alert);

but I want to get all the system available tones and choose a one between them.

Upvotes: 2

Views: 1522

Answers (1)

Ronish
Ronish

Reputation: 404

This worked for me :

Uri ringtone= RingtoneManager.getActualDefaultRingtoneUri(YourActivity.this, RingtoneManager.TYPE_ALARM);


And as stated by this answer, you have to do the following:

Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtone);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, ringtone);
startActivityForResult(intent , 1);

And finally you get the selected tone "uri" which you can store in ringtone as shown below in onActivityResult()

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case 1:
            ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            break;    
        default:
            break;
        }
    }
}

Upvotes: 3

Related Questions