现在很多应用都会用到悬浮窗,很多国产rom把悬浮窗权限加入控制了,你就需要判断是否有悬浮窗权限,然后做对应操作。
Android 原生有自带权限管理的,只是被隐藏了。看android源码在android.app下就有个AppOpsManager类。
类说明如下:
/** * API for interacting with "application operation" tracking. * * <p>This API is not generally intended for third party application developers; most * features are only available to system applications. Obtain an instance of it through * { @link Context#getSystemService(String) Context.getSystemService} with * { @link Context#APP_OPS_SERVICE Context.APP_OPS_SERVICE}.</p> */上面说明了只对系统应用有用,rom厂商们应该就是利用这个AppOps机制开放一些权限控制。
我们要判断是否有权限该如何做呢?就只能通过反射去判断了。
AppOpsManager的checkOp方法,就是检测是否有某项权限的方法有这些返回值,分别是允许,忽略,错误和默认:
/** * Result from { @link #checkOp}, { @link #noteOp}, { @link #startOp}: the given caller is * allowed to perform the given operation. */ public static final int MODE_ALLOWED <