您的位置:首页 > 移动开发 > Android开发

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

2016-03-18 01:24 609 查看
最近经常有业务部的同事,投诉出错后什么提示都没有,仔细检查好发现是坑爹的他们自己把显示通知这个按钮关闭了,就是下面这个东西



关闭之后通知和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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: