通过下面的代码获取AppOpsManager MODE
private static int checkOp(Context context, int op){
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT){
Object object = context.getSystemService(Context.APP_OPS_SERVICE);
Class c = object.getClass();
try {
Class[] cArg = new Class[3];
cArg[0] = int.class;
cArg[1] = int.class;
cArg[2] = String.class;
Method lMethod = c.getDeclaredMethod("checkOp", cArg);
return (Integer) lMethod.invoke(object, op, Binder.getCallingUid(), context.getPackageName());
} catch(NoSuchMethodException e) {
e.printStackTrace();
LogUtils.e("permission:: NoSuchMethodException"+e.getMessage());
} catch (IllegalAccessException e) {
e.printStackTrace();
LogUtils.e("permission:: IllegalAccessException"+e.getMessage());
} catch (IllegalArgumentException e) {
e.printStackTrace();
LogUtils.e("permission:: IllegalArgumentException"+e.getMessage());
} catch (InvocationTargetException e) {
e.printStackTrace();
LogUtils.e("permission:: InvocationTargetException"+e.getMessage());
}
}
return -1;
}
每次通过设置界面修改 app 拨打电话权限,查看打印的值
小米 ,锤子手机正常
魅族MX5、OPPO R9S 不管怎么切换权限返回值都为0
You have found a special example. It is not recommended to make direct calls on the phone. Some mobile phones disable third-party applications to make calls directly, and instead call the system dial. The permission control below 6.0 still follows the method you listed above. It is judged based on the object and value. It cannot be operated by whether to obtain authorization for above 23.