How to open MIUI system Activity programmatically

2020-07-17 16:27发布

问题:

Is it possible to open the above page programmatically in Android?

回答1:

As far as i know there is no implicit Intent to open this Activity.

To figure out how to do this explicitly, take a look at the Logcat output when opening this menu on your device to see what is going on. The flow should be handled by the ActivityManager at some point, so you can filter for it.

You should look for something like this in the log:

I/ActivityManager: START u0 {cmp=com.miui.powerkeeper/.ui.PowerHideModeActivity} from uid 1000 on display 0

After acquiring this information, you just have to create an appropriate Intent so you could start the same Activity yourself:

try {
    Intent intent = new Intent();
    intent.setClassName("com.miui.powerkeeper",
        "com.miui.powerkeeper.ui.PowerHideModeActivity");

    startActivity(intent);
} catch (ActivityNotFoundException anfe) {
    // this is not an MIUI device, or the component got moved/renamed
}

On a side note, you shouldn't open OS components in an explicit way like this. Whenever they change the class name or package of this component, your code will break.



回答2:

MIUI 10.

For current app:

try {
    Intent intent = new Intent();
    intent.setClassName("com.miui.powerkeeper",
    "com.miui.powerkeeper.ui.HiddenAppsConfigActivity");
    intent.putExtra("package_name", getPackageName());
    intent.putExtra("package_label", getText(R.string.app_name));
    startActivity(intent);
} catch (ActivityNotFoundException anfe) {
}


回答3:

You can use jump to app detail activity on XiaoMi Phone(MIUI)

    Intent intent = new Intent(); 
    intent.setClassName("com.miui.securitycenter", "com.miui.appmanager.ApplicationsDetailsActivity");
    intent.putExtra("package_name", packageName);
    intent.putExtra("package_label", "Dev Tools");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

This is used by Dev Tools App, https://play.google.com/store/apps/details?id=cn.trinea.android.developertools