Example usage for android.media RingtoneManager TYPE_RINGTONE

List of usage examples for android.media RingtoneManager TYPE_RINGTONE

Introduction

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

Prototype

int TYPE_RINGTONE

To view the source code for android.media RingtoneManager TYPE_RINGTONE.

Click Source Link

Document

Type that refers to sounds that are used for the phone ringer.

Usage

From source file:Main.java

public static boolean isRingtone(int type) {
    if (type == RingtoneManager.TYPE_RINGTONE) {
        return true;
    }//www. j  a v  a  2 s  . co  m
    return false;
}

From source file:Main.java

public static List<Ringtone> fetchAvailableRingtones(Context context) {

    List<Ringtone> ringtones = new ArrayList<>();
    RingtoneManager mgr = new RingtoneManager(context);
    mgr.setType(RingtoneManager.TYPE_RINGTONE);

    int n = mgr.getCursor().getCount();
    for (int i = 0; i < n; i++) {
        ringtones.add(mgr.getRingtone(i));
    }// w  ww .  ja  v a2 s  . co m

    return ringtones;
}

From source file:Main.java

public static List<Ringtone> fetchAvailableRingtones(Context context) {
    List<Ringtone> ringtones = new ArrayList<>();
    RingtoneManager ringtoneManager = new RingtoneManager(context);
    ringtoneManager.setType(RingtoneManager.TYPE_RINGTONE);

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

    for (int i = 0; i < count; i++) {
        ringtones.add(ringtoneManager.getRingtone(i));
    } // END for/*from ww w  .ja va 2 s  .c om*/

    return ringtones;
}

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);
    }/*  ww w  . j a v  a2  s . c o m*/

    return list;
}

From source file:Main.java

/**
 * Gets a specific system string based on a ringtone type
 * @param type The ringtone type//from   www .  jav  a  2 s.c o  m
 * @return A string representing the ringtone type
 */
private static String getStringByType(int type) {
    switch (type) {
    case RingtoneManager.TYPE_ALARM:
        return Settings.System.ALARM_ALERT;
    case RingtoneManager.TYPE_NOTIFICATION:
        return Settings.System.NOTIFICATION_SOUND;
    case RingtoneManager.TYPE_RINGTONE:
        return Settings.System.RINGTONE;
    default:
        return null;
    }
}

From source file:Main.java

public static boolean hasSystemDefaultRingtone(Context ctx) {
    return hasSystemDefaultRingtone(ctx, RingtoneManager.TYPE_RINGTONE);
}

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;/*w ww.  jav a 2  s.co  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 getAlarmRingtoneUri() {
    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (alert == null) {
        // alert is null, using backup
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alert == null) { // I can't see this ever being null (as always
            // have a default notification) but just incase
            // alert backup is null, using 2nd backup
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        }/*from   w w  w .jav  a  2s .  com*/
    }
    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  w w w. j  a va 2  s .  c om*/
    } // 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, String> getRingtones(@NonNull Context context) {
    return getRingtones(context, RingtoneManager.TYPE_RINGTONE);
}