android - 各位怎么处理6.0以下第三方ROM自带的权限处理机制
ringa_lee
ringa_lee 2017-04-18 09:16:53
0
1
660

通过下面的代码获取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 拨打电话权限,查看打印的值

测试结果(都是6.0以下的系统):

  1. 小米 ,锤子手机正常

  2. 魅族MX5、OPPO R9S 不管怎么切换权限返回值都为0

请问各位如何拿到当前的权限状态?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
黄舟

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template