XXPermissions icon indicating copy to clipboard operation
XXPermissions copied to clipboard

checkOpNoThrow is deprecated issue in AppOpsManager.class.getMethod("checkOpNoThrow", int.class, int.class, String.class)

Open ashirkhan94 opened this issue 7 months ago • 2 comments

Question Description [Required]

Hi could you please give a suggestion/solution for checkOpNoThrow deprecated issue

Here is my code for checking MIUI special permissions, and its working fine, but in android studio they give a deprecated waring for checkOpNoThrow They mentioned instead of using checkOpNoThrow use unsafeCheckOpNoThrow but when I use unsafeCheckOpNoThrow, I got an exception like

java.lang.IllegalArgumentException: method android.app.AppOpsManager.unsafeCheckOpNoThrow argument 1 has type java.lang.String, got java.lang.Integer
	at java.lang.reflect.Method.invoke(Native Method)

But I have no prior experience in Android side, Could you pls help me.

  public static boolean isCustomPermissionGranted(Context context, int permission) {
        Log.d(TAG,"The result is------------ ");
        try {
            AppOpsManager mgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
            Method m = AppOpsManager.class.getMethod("unsafeCheckOpNoThrow", int.class, int.class, String.class);
            int result = (int) m.invoke(mgr, permission, android.os.Process.myUid(), context.getPackageName());
            return result == AppOpsManager.MODE_ALLOWED;
        } catch (Exception e) {
            Log.d(TAG,"The result is------------ ",e);
        }
        return false;
    }

Is the issue mentioned in the framework documentation? [Required]

Not Selected

Did you consult the framework documentation but couldn't find a solution? [Required]

Not Selected

Has a similar issue been reported in the issue list? [Required]

Not Selected

Have you searched the issue list but couldn't find a solution? [Required]

Yes

ashirkhan94 avatar Jun 27 '24 06:06 ashirkhan94