我无法控制应用程序中的“在后台运行时显示弹出窗口”。我只能重定向到其他权限页面。如何检查此权限是启用还是禁用?我想查看应用程序。
此代码重定向。
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
intent.putExtra("extra_pkgname", context.getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (isIntentAvailable(intent, context)) {
context.startActivity(intent);
} else {
Log.e(TAG, "Intent is not available!");
}
这是一个确定是否被授予的有效方法(在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;
}
您可以在这里找到更详细的代码:https://github.com/zoontek/react-native-permissions/issues/412#issuecomment-1590376224