How to check "Displaying popup windows while running in the background" permission?
Asked Answered
R

1

7

I'm coding an android app that needs to start an activity in the background.

On XiaoMi device, my app must be accepted "Displaying popup windows while running in the background" permission to do that.

However, I don't know when this permission is granted to guide users to accept it. Is there any solution to check this permission is granted or not?

Thanks

enter image description here

Retaretable answered 4/12, 2020 at 4:41 Comment(1)
Does this answer your question? Permission to display pop-up windows while running in the backgroundMathildamathilde
M
0

Reposting my previously deleted answer once again

Here is a working way to find out if it's granted (tested on MIUI 14.0.3)

public static final int OP_BACKGROUND_START_ACTIVITY = 10021;

@SuppressWarnings("JavaReflectionMemberAccess")
@TargetApi(19)
public static boolean isBackgroundStartActivityPermissionGranted(Context context) {
    try {
        AppOpsManager mgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        Method m = AppOpsManager.class.getMethod("checkOpNoThrow", int.class, int.class, String.class);
        int result = (int) m.invoke(mgr, OP_BACKGROUND_START_ACTIVITY, android.os.Process.myUid(), context.getPackageName());
        return result == AppOpsManager.MODE_ALLOWED;
    } catch (Exception e) {
        Log.d("Exception", e.toString());
    }
    return true;
}

You can find an even more detailed code here: https://github.com/zoontek/react-native-permissions/issues/412#issuecomment-1590376224

Mathildamathilde answered 20/1 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.