Reputation: 2374
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.
Upvotes: 3
Views: 12625
Reputation: 38247
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);
Upvotes: 7
Reputation: 1007276
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.
Upvotes: 3