Example usage for android.media RingtoneManager ID_COLUMN_INDEX

List of usage examples for android.media RingtoneManager ID_COLUMN_INDEX

Introduction

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

Prototype

int ID_COLUMN_INDEX

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

Click Source Link

Document

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

Usage

From source file:Main.java

/**
 * Returns the system default ringtone URI {@link Uri}, or
 * the first available ringtone when the system default
 * does not exist (usually tablets).//from  w  w w  .  ja va 2s .c om
 *
 * @param ctx the {@link Context}
 * @return Uri ringtone URI
 */
public static Uri getDefaultRingtoneUri(Context ctx, int type) {
    Uri uri;

    uri = RingtoneManager.getActualDefaultRingtoneUri(ctx, type);

    if (uri == null) {
        // The default ringtone doesn't exist - probably a tablet
        // Return the first available
        RingtoneManager rm = new RingtoneManager(ctx);
        rm.setType(type);

        Cursor cursor = rm.getCursor();
        cursor.moveToFirst();

        String idString = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
        String uriString = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);

        uri = Uri.parse(uriString + '/' + idString);

        cursor.close();

        return uri;
    } else {
        // Return system default ringtone
        return uri;
    }
}

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 ww  w.  ja va 2 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();
}