Example usage for android.media RingtoneManager TITLE_COLUMN_INDEX

List of usage examples for android.media RingtoneManager TITLE_COLUMN_INDEX

Introduction

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

Prototype

int TITLE_COLUMN_INDEX

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

Click Source Link

Document

The column index (in the cursor returned by #getCursor() for the title.

Usage

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  . j  av  a2  s.  co  m*/

    return list;
}

From source file:Main.java

/**
 * Returns a map of ring tones registered on system. Map key is ring tone name,
 * value is ring tone uri./*from   w  w  w.  j  a va2  s  . co  m*/
 *
 * @param context {@link Context} used to access system data.
 * @return Map of ring tones.
 */
public static Map<String, String> getRingtones(@NonNull Context context, int type) {
    RingtoneManager manager = new RingtoneManager(context);
    manager.setType(type);
    Cursor cursor = manager.getCursor();

    Map<String, String> map = new HashMap<>();
    while (cursor.moveToNext()) {
        String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
        String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);

        map.put(notificationTitle, notificationUri);
    }

    return map;
}

From source file:mobisocial.musubi.BootstrapActivity.java

private void ensureRingtone() {
    SharedPreferences settings = getSharedPreferences(SettingsActivity.PREFS_NAME, 0);
    if (settings.getString("ringtone", null) != null) {
        return;/*from w ww .j a  v a2 s  . c o m*/
    }

    RingtoneManager ringtoneManager = new RingtoneManager(this);
    ringtoneManager.setType(RingtoneManager.TYPE_NOTIFICATION);
    String ringtoneUri = null;
    String backupUri = null;
    Cursor cursor = ringtoneManager.getCursor();
    try {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String ringtone = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
            if (ringtone.equalsIgnoreCase("dDeneb")) {
                ringtoneUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/"
                        + cursor.getString(RingtoneManager.ID_COLUMN_INDEX);

                break;
            }
            if (backupUri == null) {
                backupUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/"
                        + cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
            }
            cursor.moveToNext();
        }
    } finally {
        cursor.deactivate();
    }

    SharedPreferences.Editor editor = settings.edit();
    if (ringtoneUri != null) {
        editor.putString("ringtone", ringtoneUri);
    } else {
        if (backupUri != null) {
            editor.putString("ringtone", backupUri.toString());
        } else {
            editor.putString("ringtone", "none");
        }
    }
    editor.commit();
}