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 sharedPreferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE);

        if (!sharedPreferences.getBoolean("active", false)) {
            return;
        } // 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));
    }
}