之前开发了一个悬浮窗功能,跳转其他权限的话,然后先悬浮窗回来,发现小米的手机 回不来。
一番查找才发现 小米需要一个权限。
解决代码如下
/**
* 检查小米 从后台打开的权限
*
* @param context
* @return
*/
public static boolean isAllowed(Context context) {
AppOpsManager ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
try {
int op = 10021;
Method method = ops.getClass().getMethod("checkOpNoThrow", new Class[]{int.class, int.class, String.class});
Integer result = (Integer) method.invoke(ops, op, android.os.Process.myUid(), context.getPackageName());
return result == AppOpsManager.MODE_ALLOWED;
} catch (Exception e) {
Log.e("AppUtils", "not support");
}
return false;
}
这个 op=10021 对应的就是 后台弹出权限。
你还要看其他权限对应的op值,那你 就可以写个循坏 去判断
例如:你先把所有的权限都关闭,对比下输出的值,然后你再把你想要的那个权限打开。就能知道对应的op值。
op=10021 后台弹出权限。
op=10016 nfc 权限。
op=10017 快捷方式。