Question

if (Build.VERSION.SDK_INT > 18) {
 // I have no idea what to do... :( 



 } else { // It works good under api level 18 
   Uri DefaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);

 if (DefaultRingtoneUri != null) {
  Cursor c = getContentResolver().query(DefaultRingtoneUri, null, null, null, null);
  c.moveToFirst();
  BellName = c.getString(c.getColumnIndex(MediaStore.MediaColumns.TITLE));
  mediaURI = String.valueOf(DefaultRingtoneUri);
 } 
}

how can i get my default ringtone URI?

In else code works well on 4.3 and under versions.

Was it helpful?

Solution

this is what i am using to play the default sound.

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

see How to play ringtone/alarm sound in Android for further information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top