应用检查后台启动权限的方法如下:
public static boolean canBackgroundStart(Context context) {
AppOpsManager ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
try {
int op = 10021; // >= 23
// ops.checkOpNoThrow(op, uid, packageName)
Method method = ops.getClass().getMethod("checkOpNoThrow", new Class[]
{int.class, int.class, String.class}
);
Integer result = (Integer) method.invoke(ops, op, Process.myUid(), context.getPackageName());
return result == AppOpsManager.MODE_ALLOWED;
} catch (Exception e) {
Log.e(TAG, "not support", e);
}
return false;
}
该方法是申请“后台弹出页面”权限白名单时小米官方给出的检查后台启动权限的方法。
需要的朋友拿走
本文提供了一个检查应用是否具有后台启动权限的方法,通过调用AppOpsManager的checkOpNoThrow方法,返回结果判断权限状态。
1947

被折叠的 条评论
为什么被折叠?



