change Ringtone - Android Phone

Android examples for Phone:Sound

Description

change Ringtone

Demo Code


//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));
    }/*from w w  w.  java 2  s .co m*/
}

Related Tutorials