Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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));
    }
}