Warm tip: This article is reproduced from stackoverflow.com, please click
android android-activity

How to open MIUI system Activity programmatically in Android

发布于 2020-03-28 23:16:31

enter image description here

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

Questioner
Shaifali Rajput
Viewed
32
earthw0rmjim 2017-07-28 20:32

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.