In Android 4.0+ there is an option Settings->Accessibility-> Turn of all sounds. If I check that option, any application running on the android device will not produce any sound at all. My application has to give alarm sound, so if someone has checked that option, the app does not give any sound. So, I have to automatically un-check that option every time user launches the application. Through code, how can I do that?
It will be helpful if someone can share a piece of code. I have tried AudioManager, but that only works if mobile audio is enabled.
amanger.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
amanger.setStreamMute(AudioManager.STREAM_MUSIC, false);
amanger.setStreamVolume(AudioManager.STREAM_MUSIC,
(int)(amanger.getStreamMaxVolume(AudioManager.STREAM_MUSIC)*(75.0/100.0)), 0);
On your device, open Settings > Accessibility. Scroll until you find Accountable2You. Tap on Accountable2You. Toggle Accessibility to Off and then On again (it may show as on but still be disabled - this step will reset it).
Open your Android device's Settings app . Select Accessibility. Switch Access. At the top, select the On/Off switch.
Explore Android accessibility apps & services You can find Android Accessibility Suite on devices with Android 9 and higher. Review Android device settings for ways to customize your device. Open your device's Settings app, then choose Accessibility. Explore Google Play for accessibility apps and services for Android.
You can use following function to disable system volume
public static void disableSound(Context context)
{
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
}
If you want to enable it again, just change the parameters
audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, 10, 0);
Volume ranges from 0-10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With