Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ashirkhan94 opened this issue Jun 27, 2024 · 2 comments
Labels
question Further information is requested

Comments

@ashirkhan94
Copy link

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 ashirkhan94 added the question Further information is requested label Jun 27, 2024
@getActivity
Copy link
Owner

Hi, I'm not answering questions outside of my framework right now

@ashirkhan94
Copy link
Author

Hi @getActivity
Ok and thanks for your quick replay👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants