Java tutorial
//package com.java2s; import android.content.Context; import android.media.AudioManager; import android.util.Log; public class Main { static int currentVolume; static int currentMode; public static void setRingerModeBack(Context context) { if (currentMode == AudioManager.RINGER_MODE_NORMAL) { setRinger2Normal(context); Log.i("Restored Mode normal", currentVolume + ""); } else if (currentMode == AudioManager.RINGER_MODE_VIBRATE) { setRinger2Vibrate(context); Log.i("Restored Mode vibrate", currentVolume + ""); } else if (currentMode == AudioManager.RINGER_MODE_SILENT) { setRinger2Silent(context); Log.i("Restored Mode Silent", currentVolume + ""); } else { Log.i("Nothing ", "Matched above"); } } public static void setRinger2Normal(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); //setting the volume audioManager.setStreamVolume(AudioManager.STREAM_RING, currentVolume, 0); Log.i("HelperFunctions ", "Normal method called"); } public static void setRinger2Vibrate(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); Log.i("HelperFunctions ", "Vibrate method called"); } public static void setRinger2Silent(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); Log.i("HelperFunctions ", "Silent method called"); } }