2

I am trying to enable Accessibility setting for my application as soon as the application is launched. But I am not able to do it currently. I have used the following code:

 Settings.Secure.putString(getContentResolver(), 
                           Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, 
                           "package_name");
 Settings.Secure.putString(getContentResolver(), 
                           Settings.Secure.ACCESSIBILITY_ENABLED, 
                           "1");

To use this code snippet we have to declare the following permission:

WRITE_SECURE_SETTINGS, but this permission is applicable only for system applications. How can I achieve the same functionality for my application. All suggestions are welcome.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
keshav kowshik
  • 2,354
  • 4
  • 22
  • 45

2 Answers2

7

The API says: Settings.Secure are

for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications.

If you want to check programmatically to prompt the user, see also android-how-do-you-check-if-a-particular-accessibilityservice-is-enabled. The code to call the intent is given for example in how-to-programmatically-enable-disable-accessibility-service-in-android, it is

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);
Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188
3

How can I achieve the same functionality for may application

You can't, for blindingly obvious privacy and security reasons. An AccessibilityService has extensive access to what a user does with the device's user interface, and for that reason, the user has to agree to enable it as a separate action through the Settings app.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Ok. Once the user enables it, Can I mask it from again disabling it? Is it possible? – keshav kowshik Aug 14 '15 at 12:38
  • 1
    @Keshav1234: "Can I mask it from again disabling it?" -- hopefully no, for the same blindingly obvious privacy and security reasons. – CommonsWare Aug 14 '15 at 12:42
  • Ok. Thanks a lot commonsware. I have one more doubt, in Android M they have removed reading and writing bookmarks, is there an alternative for that? – keshav kowshik Aug 14 '15 at 12:48
  • @Keshav1234: "they have removed reading and writing bookmarks" -- I am not aware that they have. If that is indeed true, I will be very pleased. I am certainly not aware of a workaround. – CommonsWare Aug 14 '15 at 12:50
  • 1
    Yes, They have. Please see the following link, It says Bookmarks and subscribed Feeds permissions removed. http://developer.android.com/preview/support.html. – keshav kowshik Aug 14 '15 at 12:52
  • 1
    @Keshav1234: Ah, I missed that in the MNC v2 release notes. Thanks for pointing it out! – CommonsWare Aug 14 '15 at 12:57