Check permissions on xiaomi device with a version below api 23

1.4k Views Asked by At

As you know, Xiaomi devices have their own system of permissions. I'm testing my application on the device xiaomi redmi 3, api 22, android 5.1.1. I want to check if there is permission to access the camera and audio. But the standard way does not work:

ContextCompat.checkSelfPermission(getActivity().getApplicationContext(), "android.permission.CAMERA");

returns 0, although this is not true.

I found another way, but it also does not work correctly:

boolean b = hasSelfPermissionForXiaomi(getActivity(),"android.permission.CAMERA");

    private boolean hasSelfPermissionForXiaomi(Context context,String permission){
    String permissionTop = AppOpsManagerCompat.permissionToOp(permission);
    if(permissionTop == null){
        // not dangerous
        return true;
    }
    int noteOp = AppOpsManagerCompat.noteOp(context,permissionTop, Process.myUid(),context.getPackageName());
    return noteOp == AppOpsManagerCompat.MODE_ALLOWED && checkSelfPermission(context,permission) == PackageManager.PERMISSION_GRANTED;
}

b = true, although this is not true.

Guys, did any of you understand how to check permissions on xiaomi devices ???

0

There are 0 best solutions below