Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.media.AudioManager;

import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;

public class Main {
    private static Ringtone ringtone = null;

    public static void playRingtone(Context context, int type) {
        //        mediaPlayer = MediaPlayer.create(context, getDefaultRingtoneUri(context, type));
        //        mediaPlayer.setLooping(true);
        //        mediaPlayer.setVolume(100, 100);
        //        mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
        //
        //        mediaPlayer.start();

        ringtone = getDefaultRingtone(context, type);
        ringtone.setStreamType(AudioManager.STREAM_RING);
        ringtone.play();

    }

    private static Ringtone getDefaultRingtone(Context context, int type) {
        return RingtoneManager.getRingtone(context, getDefaultRingtoneUri(context, type));
    }

    private static Uri getDefaultRingtoneUri(Context context, int type) {
        return RingtoneManager.getActualDefaultRingtoneUri(context, type);
    }
}