此方法可以判断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;
	}
    }


更多相关文章

  1. 做自己的Android ROM,屏蔽对framework中的系统APK的签名检查
  2. Android系统启动流程 -- android
  3. Android 通过Volley 模拟登录教务系统 出错,出错原因:系统正忙
  4. Android_照相机Camera_调用系统照…
  5. 尝试在安卓系统中获得USSD响应
  6. Android下usb host接口插入usb设备时,如何屏蔽usb权限的提示框? 如
  7. android手机联网时会有什么系统广播发出呢??
  8. [置顶] Android系统的样式style
  9. Android实现一键复制粘贴,兼容低版本系统(api 11以下)

随机推荐

  1. css选择在IE中不起作用
  2. 注入html行模板的最佳方法
  3. require():使用module.exports vs直接分配给
  4. iOS uiwebview无法从javascript方法加载
  5. 为什么括号用于包装javascript函数调用? [
  6. js 不同类型var的boolean运算验证
  7. Ajax中DWR框架使用简单步骤
  8. 为什么推荐把<script>元素写在body里面
  9. js运算符的优先级
  10. 理解javascript全局命名空间和闭包