set Audio Silent Mode - Android Media

Android examples for Media:Audio Mode

Description

set Audio Silent Mode

Demo Code


//package com.java2s;
import android.content.Context;
import android.media.AudioManager;

public class Main {
    public static final String MODE_SILENT = "silent";
    public static final String MODE_VIBRATE = "vibrate";

    public static void setSilentMode(final Context context,
            final String strMode) {
        final AudioManager am = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);

        if (strMode.equals(MODE_SILENT)) {
            am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        } else if (strMode.equals(MODE_VIBRATE)) {
            am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        } else {//from  w  w  w .jav  a  2  s  .  c om
            am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
    }
}

Related Tutorials