33

I am developing an Android APP based on Accessibility feature. As it can't programmatically Enable/Disable Accessibility Service in Android(See How to Programmatically Enable/Disable Accessibility Service in Android) , So I guide the user to Accessibility Settings Page(Pic 1) via the code below:

public static boolean gotoAccessibilitySettings(Context context) {
    Intent settingsIntent = new Intent(
            Settings.ACTION_ACCESSIBILITY_SETTINGS);
    if (!(context instanceof Activity)) {
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    boolean isOk = true;
    try {
        context.startActivity(settingsIntent);
    } catch (ActivityNotFoundException e) {
        isOk = false;
    }
    return isOk;
}

And then the user need to find out the Sub Settings Label of my APP, click it, and now the Accessibility Settings Page of my APP show(Pic 2).

I doubt that if any way start my APP's Accessibility Settings Page(Pic 2) directly?

Community
  • 1
  • 1
Kalok Lo
  • 343
  • 1
  • 3
  • 7

3 Answers3

25

You can manually open the accessibility settings with the following Intent (when android.content.Intent and android.app.Intent have both been imported):

Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivity(intent);

Check out the following resources for more information:

Tim Groeneveld
  • 8,739
  • 3
  • 44
  • 60
  • 19
    Thanks for your answer, @timgws. But my problem is open the accessibility settings of my own app directly, not the home page of accessibility settings :( – Kalok Lo Apr 21 '15 at 04:05
  • Ended up doing this. Until I figure out a better way to get to the page, I just tell the user to click on my app and enable the service from settings. – Thor Lancaster Mar 21 '20 at 05:45
4

Try this:

Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Shubham Goel
  • 1,962
  • 17
  • 25
0

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:

  • @money zhang what should i type in the "the fragment which you want show"? i want to enter my own accessibility service settings.. – Didi78 Jun 30 '15 at 15:51
  • I tried my app name, package name service class name and etc instead of "the fragment which you want show". please tell what should I type? – David Aug 04 '15 at 06:15
  • 3
    According to that link, this method no longer works as the vulnerability has been patched in Android 4.4 Kitkat – BamsBamx Sep 28 '16 at 23:18