Example usage for android.media RingtoneManager getRingtoneUri

List of usage examples for android.media RingtoneManager getRingtoneUri

Introduction

In this page you can find the example usage for android.media RingtoneManager getRingtoneUri.

Prototype

public Uri getRingtoneUri(int position) 

Source Link

Document

Gets a Uri for the ringtone at the given position in the Cursor .

Usage

From source file:Main.java

public static void changeRingtone(Context context) {

    SharedPreferences preferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE);
    if (!preferences.getBoolean("active", false))
        return;//from  www  . ja v  a 2 s.  c  o m

    RingtoneManager mgr = new RingtoneManager(context);
    Random random = new Random(System.currentTimeMillis());

    int n = random.nextInt(mgr.getCursor().getCount());

    RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, mgr.getRingtoneUri(n));
}

From source file:Main.java

public static Uri getRandomRingtone(Context context) {
    Uri alert = null;/*  ww  w .  jav a 2  s . c om*/
    RingtoneManager ringtoneManager = new RingtoneManager(context);
    ringtoneManager.setType(RingtoneManager.TYPE_ALARM);
    int count = ringtoneManager.getCursor().getCount();
    int attempts = 0;
    do {
        int random = (int) Math.random() * (count + 1);
        alert = ringtoneManager.getRingtoneUri(random);
    } while (alert == null && ++attempts < 5);
    return alert;
}

From source file:Main.java

public static void changeRingtone(Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE);

    if (!sharedPreferences.getBoolean("active", false)) {
        return;//from  ww w. j  a  va  2  s  .co m
    } // END if

    RingtoneManager ringtoneManager = new RingtoneManager(context);
    Random random = new Random(System.currentTimeMillis());

    int count = random.nextInt(ringtoneManager.getCursor().getCount());

    RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE,
            ringtoneManager.getRingtoneUri(count));
}

From source file:Main.java

public static Map<String, Uri> getRingtones(Activity activity) {
    RingtoneManager manager = new RingtoneManager(activity);
    manager.setType(RingtoneManager.TYPE_RINGTONE);
    Cursor cursor = manager.getCursor();

    Map<String, Uri> list = new LinkedHashMap<>();
    while (cursor.moveToNext()) {
        String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
        Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());

        list.put(notificationTitle, notificationUri);
    }/*from w w w. ja v a 2s.  c o  m*/

    return list;
}

From source file:org.getlantern.firetweet.preference.RingtonePreference.java

private void loadRingtones(final Context context) {
    final RingtoneManager manager = new RingtoneManager(context);
    manager.setType(RingtoneManager.TYPE_NOTIFICATION);
    final Cursor cur = manager.getCursor();
    cur.moveToFirst();//from   w w  w  .  ja v  a  2 s.  c om
    final int count = cur.getCount();
    mRingtones = new Ringtone[count + 1];
    mEntries = new String[count + 1];
    mValues = new String[count + 1];
    final Uri default_uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    final Ringtone default_ringtone = RingtoneManager.getRingtone(context, default_uri);
    mRingtones[0] = default_ringtone;
    mEntries[0] = context.getString(R.string.default_ringtone);
    mValues[0] = default_uri.toString();
    for (int i = 0; i < count; i++) {
        final Ringtone ringtone = manager.getRingtone(i);
        mRingtones[i + 1] = ringtone;
        mEntries[i + 1] = ringtone.getTitle(context);
        mValues[i + 1] = manager.getRingtoneUri(i).toString();
    }
    setEntries(mEntries);
    setEntryValues(mValues);
    cur.close();
}