1. 在有些情况下,要检测系统是否禁止app显示通知,可以调用一下方法

/** * 检查是否可以显示通知 * @return */  public boolean isNotificationEnabled() {AppOpsManager mAppOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);ApplicationInfo appInfo = mContext.getApplicationInfo();String pkg = mContext.getApplicationContext().getPackageName();int uid = appInfo.uid;Class appOpsClass = null; /* Context.APP_OPS_MANAGER */try {appOpsClass = Class.forName(AppOpsManager.class.getName());Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class);Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);int value = (int)opPostNotificationValue.get(Integer.class);return ((int)checkOpNoThrowMethod.invoke(mAppOps,value, uid, pkg) == AppOpsManager.MODE_ALLOWED);}  catch (Exception e) {e.printStackTrace();}return false;  }


更多相关文章

  1. Android工程获取bulid.xml文件的方法
  2. [读书笔记]Android LayoutInflater.inflate方法参数详解原理分析
  3. Error occurred during initialization of VM解决方法(Android S
  4. Android中的使用ListView控件显示List集合中的数据,并对Item响应
  5. Android使用httpPost向服务器发送请求的方法
  6. 设置图片缩放方法失效 解决办法设置android:scaleType属性
  7. XAMARIN Android获取WIFIMAC地址的方法
  8. 实时获取Android 各版本电量的统一方法

随机推荐

  1. Handler消息机制 源码解读
  2. 完美解决 No toolchains found in the ND
  3. Android动画AnimationSet遇到的问题。
  4. Flutter 在 Android(安卓)Studio下环境配
  5. Android开发中Material Design风格设置页
  6. Android(安卓)Studio的快捷键
  7. Android之常见图标尺寸
  8. 自定义字体主题+自定义背景+设置radiobut
  9. Android(安卓)设计模式之适配器模式
  10. Android(安卓)Studio配置打包生成自定义