how can I detect whether the android phone in Silent mode programmatically
Use the getRingerMode()
method in AudioManager
.
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
Log.i("MyApp","Silent mode");
break;
case AudioManager.RINGER_MODE_VIBRATE:
Log.i("MyApp","Vibrate mode");
break;
case AudioManager.RINGER_MODE_NORMAL:
Log.i("MyApp","Normal mode");
break;
}
How to check if phone is mute, vibrate or loud in android
try this:
switch( audio.getRingerMode() ){
case AudioManager.RINGER_MODE_NORMAL:
break;
case AudioManager.RINGER_MODE_SILENT:
break;
case AudioManager.RINGER_MODE_VIBRATE:
break;
}
Design an application that sets the device in silent mode at a specified time
How to make the application knows that the time has come to make the
phone silent (when the application is closed)
One word: AlarmManager
how to make the application works and converts the phone to silent
mode when the time comes
The AlarmManager
mentionned above will launch your app at the set up time. To silence the phone, check the following question: Automatically silence the sound volume of Android Phone programmatically?
Is it possible to turn off the silent mode programmatically in android?
Solution for you .
AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
//For Normal mode
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
//For Silent mode
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
//For Vibrate mode
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Related Topics
Why Use Android Picasso Library to Download Images
Uploading a Large File in Multipart Using Okhttp
Android: How to Remove Margin/Padding in Preference Screen
Converting Bitmap to Bytearray Android
How to Set a Font for the Options Menu
Android: How to Get Value of an Attribute in Code
How to Prevent an Application from Being Uninstalled
Android: Using Webview Outside an Activity Context
Register Application Class in Manifest
Android: Set Color of Checkbox
Set Edittext Digits Programmatically
Source of Android's Lock Screen
How to Set Textinputlayout Error Message Colour
Sniffing/Logging Your Own Android Bluetooth Traffic
Android Studio Gradle Icon Error, Manifest Merger
Force Update of an Android App When a New Version Is Available