Back to project page SoundScheduler.
The source code is released under:
GNU General Public License
If you think the Android project SoundScheduler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Sound Scheduler//from w w w. j a v a 2 s . c o m * Copyright (C) 2013 Victor Kifer */ package com.victorkifer.SoundScheduler.managers; import android.content.Context; import android.content.Intent; import android.media.AudioManager; import android.os.Build; import android.provider.Settings; public class SoundManager { private Context context; private AudioManager audioManager; public SoundManager(Context context) { this.context = context.getApplicationContext(); audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } public void setVibrateMode() { audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } public void setSilentMode() { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } public void setNormalMode() { audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } public boolean isVibrateModeEnabled() { return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE); } public boolean isSilentModeEnabled() { return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT); } public boolean isNormalModeEnabled() { return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL); } public void setAirplaneModeOn() { setAirplaceMode(1); } public void setAirplaneModeOff() { setAirplaceMode(0); } @SuppressWarnings("deprecation") public boolean isAirplaneModeOn() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; } else { return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0; } } @SuppressWarnings("deprecation") private void setAirplaceMode(int value) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { Settings.System.putInt( context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, value); } else { Settings.Global.putInt( context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, value); } Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); boolean enabled = value > 0; intent.putExtra("state", enabled); context.sendBroadcast(intent); } }