List of usage examples for android.media RingtoneManager URI_COLUMN_INDEX
int URI_COLUMN_INDEX
To view the source code for android.media RingtoneManager URI_COLUMN_INDEX.
Click Source Link
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 www.j a v a2s . com * * @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:Main.java
/** * Returns the system default ringtone URI {@link Uri}, or * the first available ringtone when the system default * does not exist (usually tablets).// w ww .jav a 2 s . c o m * * @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 w w w. jav a 2 s. co 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(); }