thomas.fogh
thomas.fogh

Reputation: 369

How to play the "Positive" alarm sound?

How do I play the "Positive" alarm sound? I know how to play the default one...

Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
if (ringtone != null) {
    ringtone.play();
}

EDIT: Tried the below but the cursor just returns the same uri???

    RingtoneManager rm = new RingtoneManager(getApplicationContext());
    rm.setType(RingtoneManager.TYPE_ALARM);
    Cursor c = rm.getCursor();
    c.moveToFirst();
    if (!c.isAfterLast()) {
        do {
            int uriIndex = c.getInt(RingtoneManager.URI_COLUMN_INDEX);
            Uri ring = rm.getRingtoneUri(uriIndex);
            Log.d("TC", ring.toString());
        } while (c.moveToNext());
    }

Upvotes: 0

Views: 1271

Answers (2)

biegleux
biegleux

Reputation: 13247

RingtoneManager.URI_COLUMN_INDEX is a TEXT column.

RingtoneManager rm = new RingtoneManager(getApplicationContext());
rm.setType(RingtoneManager.TYPE_ALARM);
Cursor c = rm.getCursor();
c.moveToFirst();
if (!c.isAfterLast()) {
    do {
        int uriString = c.getString(RingtoneManager.URI_COLUMN_INDEX);
        Log.d("TC", uriString);
    } while (c.moveToNext());
}

Upvotes: 0

patthoyts
patthoyts

Reputation: 33193

The RingtoneManager.getCursor() function provides a cursor that will let you iterate over all the ringtones and you can check the ringtone title for a matching name. The uri's returned depend on where the ringtone was stored but once the right one is found you can save the uri as a preference. Code I have (using a preference) doesn't do anything very fancy:

Uri alert;
String alarmname = mPrefs.getString(getString(R.string.pref_sound_key, null);
if (alarmname != null && !alarmname.equals(""))
    alert = Uri.parse(alarmname);

elsewhere you can use the ringtone preferences to save a user choice and should be able to arrange the default to be "Positive" once you work out what the uri looks like.

Upvotes: 1

Related Questions