android 显示通知关闭之后,Toast不显示的状态检测

来源:互联网 发布:最新手机淘宝怎么开店 编辑:程序博客网 时间:2024/05/16 06:53

最近经常有业务部的同事,投诉出错后什么提示都没有,仔细检查好发现是坑爹的他们自己把显示通知这个按钮关闭了,就是下面这个东西
这里写图片描述
关闭之后通知和toast都不显示了,于是老大让我去找找有没有办法检测这个按钮的状态,先把检测代码贴上

/**     * @param context     * @return true 代表有有权限,或者检测失败   返回false代表没有权限     */    public static boolean checkPermission(Context context) {        if (Build.VERSION.SDK_INT < 18 || Build.VERSION.SDK_INT > 22) {            return true;        }        AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);        Class<? extends AppOpsManager> class1 = mAppOps.getClass();        try {            Method method = class1.getDeclaredMethod("noteOpNoThrow", int.class, int.class, String.class);            if (method.invoke(mAppOps, 11, Binder.getCallingUid(), context.getPackageName()).equals(AppOpsManager.MODE_ALLOWED)) {                return true;            } else {                return false;            }        } catch (NoSuchMethodException e) {            e.printStackTrace();            return true;        } catch (IllegalAccessException e) {            e.printStackTrace();            return true;        } catch (IllegalArgumentException e) {            e.printStackTrace();            return true;        } catch (InvocationTargetException e) {            e.printStackTrace();            return true;        }    }
0 0
原创粉丝点击