List of usage examples for android.media RingtoneManager RingtoneManager
public RingtoneManager(Context context)
From source file:Main.java
public static Uri getRandomRingtone(Context context) { Uri alert = null;/*from w w w . ja v a2 s.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 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 w w w.java 2 s.c om*/ 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//w w w . ja va 2 s . c o m 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); }//w w w. ja v a 2s. c o m return list; }
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;/*from w w w . ja v a2 s.c o 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 void changeRingtone(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE); if (!sharedPreferences.getBoolean("active", false)) { return;// w w w. ja 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
/** * 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.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: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 ww . ja va2 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:com.manumanu.alarmexample2.AlarmNotification.java
@Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); getWindow().addFlags(/*from w w w. jav a 2s . c o m*/ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); setContentView(R.layout.notification); mDateTime = new DateTime(this); mTextView = (TextView) findViewById(R.id.alarm_title_text); dissmiss = (Button) findViewById(R.id.dismiss_alarm); dissmiss.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { stop(); } }); readPreferences(); mRingtoneManager = new RingtoneManager(this); mRingtone = mRingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI); if (mVibrate) mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); start(getIntent()); }
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. ja v a 2 s. c o m*/ 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(); }