Android examples for Phone:Sound
change Ringtone
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.media.RingtoneManager; import java.util.Random; public class Main { public static void changeRingtone(Context context) { SharedPreferences preferences = context.getSharedPreferences( "randomizer", Context.MODE_PRIVATE); if (!preferences.getBoolean("active", false)) return; 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)); }/* w w w . j a v a 2 s . c om*/ }