Android examples for android.media:RingtoneManager
get Random Ringtone
import android.content.Context; import android.media.RingtoneManager; import android.net.Uri; public class Main { public static Uri getRandomRingtone(Context context) { Uri alert = null;//from w w w.j a v a 2s .co 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; } }