Java tutorial
//package com.java2s; import android.content.Context; import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Vibrator; import android.util.Log; public class Main { private static MediaPlayer player; private static Vibrator vibrator; private static int mUserVolume = -1; public static void silentAlarm(Context context) { if (player != null) { Log.i("AlarmHelper", "silented"); try { if (player.isLooping()) { player.setLooping(false); } player.pause(); player.stop(); player.release(); } catch (IllegalStateException e) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); } // player.setVolume(0, 0); AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_ALARM, mUserVolume, 0); } else { Log.i("AlarmHelper", "ring zero"); AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); } if (vibrator != null) { vibrator.cancel(); } else { vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.cancel(); } } }