Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open MIUI system Activity programmatically in Android

enter image description here

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

like image 807
Shaifali Rajput Avatar asked Dec 13 '22 21:12

Shaifali Rajput


2 Answers

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) {
}
like image 173
Small-fan Avatar answered Feb 15 '23 22:02

Small-fan


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.

like image 32
earthw0rmjim Avatar answered Feb 16 '23 00:02

earthw0rmjim