List of usage examples for android.media RingtoneManager getCursor
public Cursor getCursor()
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)); }//from ww w .ja v a 2 s. co m return ringtones; }
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 ww . j a va 2 s . c o 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:Main.java
public static Uri getRandomRingtone(Context context) { Uri alert = null;// ww w. j a v a 2s. c o m 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 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); }/* www. j a va2 s.c om*/ return list; }
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 www.j a v a2 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:Main.java
public static void changeRingtone(Context context) { SharedPreferences preferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE); if (!preferences.getBoolean("active", false)) return;/*www. j a v 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 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 w ww. j a v a 2 s .c om*/ return ringtones; }
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;/* w w w . ja v a 2 s .c o 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: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.j a v a 2s .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(); }
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 . ja va 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(); }