Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Programmatically Enable/Disable Accessibility Service in Android

I would like to programmatically enable/disable Accessibility Services listed under Settings->Accessibility option.

I could start Accessibility Intent like below:

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); startActivityForResult(intent, 0); 

But I don't have any idea on how to enable the services listed in the view through my code.

Please, provide me your views.

like image 622
Abilash Avatar asked Apr 08 '12 07:04

Abilash


People also ask

How do I turn off accessibility services?

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

How do I enable accessibility service?

To access the Accessibility features on your Android device open the Settings app . In the Settings app, select Accessibility from the list. On the Accessibility screen, scroll down to the Interaction controls section and select Accessibility Menu. On the next screen, set the toggle switch for Accessibility Menu to On.

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


2 Answers

I found a solution worked for me by calling

Settings.Secure.putString(getContentResolver(),      Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "pkgname/classname"); Settings.Secure.putString(getContentResolver(),      Settings.Secure.ACCESSIBILITY_ENABLED, "1"); 

Where the pkgname is your package name and the classname is the class name of your accessibility service.

If you need to enable several services or you don't want to destory the previous settings you might want to use : to seperate other services.

Also you might need to run as a system application and you might need the following permissions

<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> 

However, according to @Rupert Rawnsley this might not work on some versions of Android, I am working on Android 4.0.4 and hope it works for you.

PS. If it doesn't work, maybe you could find some luck in /data/data/com.android.providers.settings/databases/settings.db/secure, that's where Android stores secure settings.

like image 69
Kevin Avatar answered Sep 18 '22 12:09

Kevin


From Android 6.0 you can use:

adb shell settings put secure enabled_accessibility_services packagname/servicename 

The settings.db from old releases is no longer present on Android 6.0.

like image 26
Zoli_K Avatar answered Sep 16 '22 12:09

Zoli_K