How to start activity from background in android 10 - android Q - MIUI 11
Asked Answered
P

0

16

I have problem with starting activity from background in android 10 - android Q - MIUI 11 on real device. In this thread: start activity background in android 10 I found information how to do this on Android 10 and everything working perfectly on emulator.

I tested this on Xiaomi Mi 9T Pro with Android 10 (MIUI 11) and seems that this doesn't work.

In logcat I have following logs:

-W/ActivityTaskManager: Background activity start for com.com.app allowed because SYSTEM_ALERT_WINDOW permission is granted.
-D/ActivityTaskManagerServiceInjector: MIUILOG- Permission Denied Activity : Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.android.chrome cmp=com.android.chrome/com.google.android.apps.chrome.Main } pkg : com.com.app uid : 10283 tuid : 10052

Why this not working on xiaomi device?

Edit:

I have found solution. In MIUI there is additional permission which should be turned on. It's called: Display pop-up windows while running in the background. This is code to show window with this permission:

First I'm checking if user have MIUI installed on phone:

public static boolean isMiUi() {
    return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
}

public static String getSystemProperty(String propName) {
    String line;
    BufferedReader input = null;
    try {
        java.lang.Process p = Runtime.getRuntime().exec("getprop " + propName);
        input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
        line = input.readLine();
        input.close();
    } catch (IOException ex) {
        return null;
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return line;
}

If yes then window with permissions can be shown:

 private void showPermissionsDialog() {
    Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
    intent.setClassName("com.miui.securitycenter",
            "com.miui.permcenter.permissions.PermissionsEditorActivity");
    intent.putExtra("extra_pkgname", getPackageName());
    startActivity(intent);
}

Now I need to check if user granted this permission because I don't want to show this window every time when app is started. Anyone know how to do this?

Potpie answered 29/1, 2020 at 20:18 Comment(4)
I don't know why you been downvoted. I'm facing same issue and there is no documentation about this. Only affects miui as my app works correctly on other devices.Ruffian
use this: How to open Draw Overlay permission popup in MIUI?Tarmac
I have the same issue but configuring the security settings on MIUI did not fix the problem.Propertied
System.exit(2);Germainegerman

© 2022 - 2024 — McMap. All rights reserved.