当前位置: 首页 > news >正文

佛山做外贸网站的公司外贸品牌推广公司

佛山做外贸网站的公司,外贸品牌推广公司,网站建设 建站知识,浙江网架公司现在很多应用都会用到悬浮窗#xff0c;很多国产rom把悬浮窗权限加入控制了#xff0c;你就需要判断是否有悬浮窗权限#xff0c;然后做对应操作。Android 原生有自带权限管理的#xff0c;只是被隐藏了。看android源码在android.app下就有个AppOpsManager类。类说明如下很多国产rom把悬浮窗权限加入控制了你就需要判断是否有悬浮窗权限然后做对应操作。Android 原生有自带权限管理的只是被隐藏了。看android源码在android.app下就有个AppOpsManager类。类说明如下/*** API for interacting with application operation tracking.** 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}.*/上面说明了只对系统应用有用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 0;/*** Result from {link #checkOp}, {link #noteOp}, {link #startOp}: the given caller is* not allowed to perform the given operation, and this attempt should* silently fail (it should not cause the app to crash).*/public static final int MODE_IGNORED 1;/*** Result from {link #checkOpNoThrow}, {link #noteOpNoThrow}, {link #startOpNoThrow}: the* given caller is not allowed to perform the given operation, and this attempt should* cause it to have a fatal error, typically a {link SecurityException}.*/public static final int MODE_ERRORED 2;/*** Result from {link #checkOp}, {link #noteOp}, {link #startOp}: the given caller should* use its default security check. This mode is not normally used; it should only be used* with appop permissions, and callers must explicitly check for it and deal with it.*/public static final int MODE_DEFAULT 3;只有MODE_ALLOWED才是确定有权限的。类里面checkOp方法如下三个参数分别是操作iduid和包名/*** Do a quick check for whether an application might be able to perform an operation.* This is not a security check; you must use {link #noteOp(int, int, String)}* or {link #startOp(int, int, String)} for your actual security checks, which also* ensure that the given uid and package name are consistent. This function can just be* used for a quick check to see if an operation has been disabled for the application,* as an early reject of some work. This does not modify the time stamp or other data* about the operation.* param op The operation to check. One of the OP_* constants.* param uid The user id of the application attempting to perform the operation.* param packageName The name of the application attempting to perform the operation.* return Returns {link #MODE_ALLOWED} if the operation is allowed, or* {link #MODE_IGNORED} if it is not allowed and should be silently ignored (without* causing the app to crash).* throws SecurityException If the app has been configured to crash on this op.* hide*/public int checkOp(int op, int uid, String packageName) {try {int mode mService.checkOperation(op, uid, packageName);if (mode MODE_ERRORED) {throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));}return mode;} catch (RemoteException e) {}return MODE_IGNORED;}操作id即op可以在该类中找到静态值定义android23里面有62种权限我们需要的是OP_SYSTEM_ALERT_WINDOW24知道这些就可以用反射把我们的方法写出了/*** 判断 悬浮窗口权限是否打开** param context* return true 允许 false禁止*/public static boolean getAppOps(Context context) {try {Object object context.getSystemService(appops);if (object null) {return false;}Class localClass object.getClass();Class[] arrayOfClass new Class[3];arrayOfClass[0] Integer.TYPE;arrayOfClass[1] Integer.TYPE;arrayOfClass[2] String.class;Method method localClass.getMethod(checkOp, arrayOfClass);if (method null) {return false;}Object[] arrayOfObject1 new Object[3];arrayOfObject1[0] Integer.valueOf(24);arrayOfObject1[1] Integer.valueOf(Binder.getCallingUid());arrayOfObject1[2] context.getPackageName();int m ((Integer) method.invoke(object, arrayOfObject1)).intValue();return m AppOpsManager.MODE_ALLOWED;} catch (Exception ex) {}return false;}测试在魅族华为小米大部分机型上都是可以的但这个方法也不能保证正确一些机型上会返回错误即MODE_ERRORED就是获取不到权限值这个方法就返回了false但实际上悬浮窗是可以使用的。以上这篇Android 获取判断是否有悬浮窗权限的方法就是小编分享给大家的全部内容了希望能给大家一个参考也希望大家多多支持。
http://www.pierceye.com/news/729143/

相关文章:

  • 北京php网站制作网站群建设思路
  • 企业建设网站的必要性小程序平台介绍怎么写
  • 网站界面设计应该遵循的原则贵州省住房和城乡建设厅网站报名网
  • 南昌建设医院官方网站国外做外链常用的网站
  • 淘宝店采用哪些方法做网站推广专门做网站的软件
  • 网站的ftp怎么查中国视觉设计网
  • 商城网站流量wordpress安装后做什么
  • 自己建网站要花多少钱wordpress采集发布接口
  • 个人网站做交易类的赚钱吗达人室内设计网论坛
  • 网站后台使用培训怎么样做微信公众号
  • 北京望京企业网站建设八佰yy影视
  • 在百度上做个网站需要多少钱创易网络
  • 网站建设神器帮人做网站犯法
  • 企业网站的特点是小程序开发文档微信小程序
  • 哈尔滨 建网站mvc做的网站如何发布访问
  • 江苏盐城网站开发百度快照首页
  • 中职网站建设课件青岛网站制作
  • 效果最好h5制作软件seo整站优化技术培训
  • 中国建设银行积分换购网站网站开发培训哪个好
  • 张家港网站建设培训wordpress电子报
  • 用dw制作学校网站教程网站优化排名方案
  • 手机图片网站模板工商营业执照网上申报
  • 网站建立的方式是什么网络推广培训哪里的
  • vue做网站首页做网站 上海
  • 建设一个商务网站的步骤做网站购买空间多少钱
  • 哈尔滨网站制作注册公司有什么风险
  • 自己做网站不如帮别人做运营网站开发计划怎么写
  • 飘雪影视在线观看免费完整台州网站排名优化价格
  • 网站制作要钱吗seo的培训网站哪里好
  • 图片类网站如何做优化装潢设计培训中心