Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn on/off all sounds from accessibility settings programmatically in android?

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);
like image 218
akash89 Avatar asked Apr 02 '14 10:04

akash89


People also ask

How do I fix Android Accessibility settings to turn off automatically?

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).

How do I turn off Accessibility menu?

Open your Android device's Settings app . Select Accessibility. Switch Access. At the top, select the On/Off switch.

How do I add Accessibility to my Android?

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.


1 Answers

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

like image 198
Sagar Patil Avatar answered Sep 19 '22 12:09

Sagar Patil