如何查看“后台运行时显示弹出窗口”权限?

pho*_*rai 7 java mobile android miui xiaomi

我正在编写一个需要在后台启动活动的 Android 应用程序。

在小米设备上,我的应用程序必须接受“在后台运行时显示弹出窗口”权限才能执行此操作。

不过不知道什么时候授予这个权限,引导用户接受。有没有什么解决方案来检查此权限是否被授予?

谢谢

在此输入图像描述

Dan*_*iel 0

再次重新发布我之前删除的答案

这是一种确定是否已授予的工作方法(在 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;
}
Run Code Online (Sandbox Code Playgroud)

您可以在这里找到更详细的代码: https: //github.com/zoontek/react-native-permissions/issues/412#issuecomment-1590376224