How to Programmatically Enable/Disable Accessibility Service in Android

后端 未结 9 497
暗喜
暗喜 2020-11-27 15:38

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

I could start Accessibility Intent like below:

相关标签:
9条回答
  • 2020-11-27 16:05

    Just in case anybody still seeks to turn off talkback from adb when you are stuck in your lock screen entering the password or pin. One thing you can try is adb shell am force-stop com.google.android.marvin.talkback

    0 讨论(0)
  • 2020-11-27 16:10

    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.

    0 讨论(0)
  • 2020-11-27 16:11

    In Android 7 (API 24), an AccessibilityService can programmatically disable itself by calling the disableSelf() method.

    0 讨论(0)
提交回复
热议问题