Programmatically enabling/disabling accessibility settings on Android device
Only system apps can enable/disable accessibility service programatically.
System apps can directly write in settings secure db to start accessibility service.
Settings.Secure.putString(getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.packagename/com.packagename.componentname");
Following permission is required to write in settings secure db:
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
For non system apps, only way to start accessibility service is direct them to accessibility settings screen via intent and let user manually start the service :
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
How can I programmatically start and stop an AccessibilityService?
Taken from the Lifecycle section of the AccessibilityService
documentation:
The lifecycle of an accessibility service is managed exclusively by the system and follows the established service life cycle. Starting an accessibility service is triggered exclusively by the user explicitly turning the service on in device settings. After the system binds to a service, it calls
onServiceConnected()
. This method can be overriden by clients that want to perform post binding setup.An accessibility service stops either when the user turns it off in device settings or when it calls
disableSelf()
(In Android 7.0 (API 24) and later).
How Enable/Disable Accessibility Service When Lock/Unlock Screen in Android
I found the answer : https://stackoverflow.com/a/45100001/15772513
I put it on the Accessibility Service class and call disableSelf()
when the screen is unlock, and call that function in OnCreate() of AccessibilityService class.
I hope this will help you.
How can I start the Accessibility Settings Page of my APP in Android?
Maybe the code below can help you :
Intent intent = new Intent();
intent.setClassName("com.android.settings",
"com.android.settings.Settings");
intent.setAction(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
"the fragment which you want show");
intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
extras);
startActivity(intent);
Or you can search the Key Word "Fragment Injection" for more information;
Check out this link,it is useful for you case:
- http://securityintelligence.com/new-vulnerability-android-framework-fragment-injection
How to direct users for enabling accessibility service for my app
You can get them to the Accessibility screen on most devices using ACTION_ACCESSIBILITY_SETTINGS
. However:
that may not work on all devices, so you will want to just send them to Settings as a fallback, if you get an
ActivityNotFoundException
there is no way to get them straight to any given app, let alone the enable/disable screen
Related Topics
How to Check Whether the Sim Card Is Available in an Android Device
Hide Ics Back Home Task Switcher Buttons
How to Know the Size of a File Before Downloading It
Install_Failed_Shared_User_Incompatible While Using Shared User Id
Radiogroup with Two Columns Which Have Ten Radiobuttons
How to Get Activity's Content View
Creating Viewholders for Listviews with Different Item Layouts
Camera Preview Image Data Processing with Android L and Camera2 API
Seek Bar, Change Path Color from Yellow to White
Android Gcm: Same Sender Id for More Application
Android Expandablelistview - Looking for a Tutorial
How to Set Shadow to a View in Android
Does the Web View on Android Support Ssl
How to Keep an Alertdialog Open After Button Onclick Is Fired
How to Join Png with Alpha/Transparency in a Frame in Realtime
How to Add Action Bar from Support Library into Preferenceactivity
Cannot Launch Avd in Emulator:Qt Library Not Found
How to Create an Android Library Jar with Gradle Without Publicly Revealing Source Code