android 判断MIUI悬浮窗权限是否打开
16lz
2021-01-22
此方法可以判断MIUI系统是否打开悬浮窗权限
1、判断是否是MIUI系统
private boolean isMIUI() { String brand = Build.BRAND.toString(); if ("Xiaomi".equalsIgnoreCase(brand)) { return true; } return false; }
2、判断是否打开权限
private static ApplicationInfo localApplicationInfo1 = null;
private int op(Context context) { if (Build.VERSION.SDK_INT >= 19){ try { Object localObject = context .getSystemService("appops"); Class localClass = localObject.getClass(); Class[] arrayOfClass = new Class[3]; arrayOfClass[0] = Integer.TYPE; arrayOfClass[1] = Integer.TYPE; arrayOfClass[2] = String.class; Method localMethod = localClass.getMethod("checkOp", arrayOfClass); Object[] arrayOfObject = new Object[3]; arrayOfObject[0] = Integer.valueOf(24); arrayOfObject[1] = Integer.valueOf(Binder.getCallingUid()); arrayOfObject[2] = context.getPackageName(); int j = ((Integer) localMethod.invoke(localObject, arrayOfObject)).intValue(); if (j == 0) return 1; return 0; } catch (Throwable localThrowable2) { return -1; } }else{//19以下的版本的特殊处理 ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; if(!"你的app的包名".equalsIgnoreCase(cn.getPackageName())){ try { ApplicationInfo localApplicationInfo2 = FS .getInstance() .getPackageManager() .getApplicationInfo(context.getPackageName(), 0); localApplicationInfo1 = localApplicationInfo2; if (localApplicationInfo1 != null) { if ((0x8000000 & localApplicationInfo1.flags) == 0) return 0; } } catch (Throwable localThrowable1) { while (true) localApplicationInfo1 = null; } } return -1; } }
private boolean checkOp(Context context) { try { if (AppOpsManager.MODE_ALLOWED == op(context)) { return true; } else { return false; } } catch (Exception e) { return false; } } public boolean isMiuiFloaAllowed(Context context) { if (isMIUI()) { return checkOp(context); } else { return false; } }
更多相关文章
- 做自己的Android ROM,屏蔽对framework中的系统APK的签名检查
- Android系统启动流程 -- android
- Android 通过Volley 模拟登录教务系统 出错,出错原因:系统正忙
- Android_照相机Camera_调用系统照…
- 尝试在安卓系统中获得USSD响应
- Android下usb host接口插入usb设备时,如何屏蔽usb权限的提示框? 如
- android手机联网时会有什么系统广播发出呢??
- [置顶] Android系统的样式style
- Android实现一键复制粘贴,兼容低版本系统(api 11以下)