How to open system activity and press a button there?

How does an app like greenify open system activity and click a button? This activity is "Application Info", the "Force Stop" button is automatically pressed. and the app can click a button in that non-root activity .

Code for opening the "Application Information" activity:

    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", "com.package.sendinput", null);
    intent.setData(uri);
    startActivityForResult(intent, 0);

      

Then the activity opened up. To click a button there, I tried adb shell input handle 200 340 (using the same uid as my running app) but "Killed" by the system. But with root you can click a button.

Is there another way?

Thank you in advance

+3


source to share


2 answers


Edit : (guess work because I haven't done something like this myself)

Automation cleanup is done using the Accessiblity service. In a nutshell, it fetches the current content of the window and dispatches AccessibilityEvent

to the specified views: touch, focus.

Content window is described as AccessibilityWindowInfo

, which may be TYPE_APPLICATION

, TYPE_INPUT_METHOD

, TYPE_SYSTEM

.



For dispatching events to the window, it uses AccessibilityManager

to dispatch AccessibilityEvent

to any child view you received inAccessibilityWindowInfo

Reading: UiAutomation

Accessibility package

+3


source


You can start application specific app info activity by package name as follows



public void showAppDetailsActivity(String packageName) {
    final int sdkVersion = Build.VERSION.SDK_INT;
    Intent intent = new Intent();

    if (sdkVersion >= Build.VERSION_CODES.GINGERBREAD) {
        intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + packageName));
    } else {

        final String appPkgName = "com.android.settings.ApplicationPkgName";

        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        intent.putExtra(appPkgName, packageName);
    }
    startActivity(intent);
}

      

0


source







All Articles