android 判断MIUI悬浮窗权限是否打开

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


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值