在Application中添加以下代码并调用:
private boolean isAllowed() {
AppOpsManager ops = (AppOpsManager) 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, Process.myUid(), getPackageName());
return result == AppOpsManager.MODE_ALLOWED;
} catch (Exception e) {
Log.e("===", "not support");
}
return false;
}