android 应用的通知开关状态的获取

funly1234 2016-04-07 10:39:17
如题,android 4.1以上可以关闭应用通知按钮,app开发时想获取到是否被关闭,有没有办法代码实现。
...全文
1241 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dorain_Gray 2020-01-14
  • 打赏
  • 举报
回复
可以参考下这个https://www.jianshu.com/p/28b8c0391c8d public static boolean isEnableV26(Context context, String pkg, int uid) { try { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Method sServiceField = notificationManager.getClass().getDeclaredMethod("getService"); sServiceField.setAccessible(true); Object sService = sServiceField.invoke(notificationManager); Method method = sService.getClass().getDeclaredMethod("areNotificationsEnabledForPackage" , String.class, Integer.TYPE); method.setAccessible(true); return (boolean) method.invoke(sService, pkg, uid); } catch (Exception e) { return true; } }
Lipton红茶 2016-09-27
  • 打赏
  • 举报
回复
http://blog.csdn.net/zcllige/article/details/52444258 看看这个文章
earthadong 2016-09-19
  • 打赏
  • 举报
回复
该怎么使用啊,送佛送到西,给全啊,谢啦
黄小楼 2016-09-18
  • 打赏
  • 举报
回复
可以通过反射来调用
黄小楼 2016-09-18
  • 打赏
  • 举报
回复
 INotificationManager nm = INotificationManager.Stub.asInterface(
                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        boolean enabled = true; // default on
        try {
            enabled = nm.areNotificationsEnabledForPackage(mAppEntry.info.packageName);
        } catch (android.os.RemoteException ex) {
            // this does not bode well
        }
Li_Xavier 2016-09-18
  • 打赏
  • 举报
回复
同问!!
HELLODM 2016-09-18
  • 打赏
  • 举报
回复
楼上方法貌似找不到类啊。INotificationManager,难道你说的反射就是反这个?不知道版本支持是多少?
BM8979 2016-08-19
  • 打赏
  • 举报
回复
楼主解决了吗

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧