Android O适配---NotificationChannel

一,直观来看

android-o上对通知做了更细粒度的管理。根据app的业务场景将通知分类。用户可以在设置中选择接收自己感兴趣的通知。同时也可以屏蔽不喜欢的通知。先上图看看新特性。

入口:手机桌面长按(android 原生8.0)app图标,右上角出现提示“应用信息”,点击进入应用详情。如下图一:我们可以看见”应用通知“


图一

点击应用通知进入应用通知管理详情页,如下图二中类别所示:本次测试创建了三种NotificationChannel:下载,聊天,推送。每种NotificationChannel设置了不同的属性,如:重要性,是否振动等等



图二

点击图二中的下载NotificationChannel,进入NotificationChannel详情页,如图三,可以看到下载NotificationChannel的详细信息



图三

总之,android-o上对通知的管理更加细粒度,通过”管道“对通知分类,用户可以根据自己对通知的喜好选择接收特定管道的通知。



二,从源码分析


一,关键类


1.NotificationManagerService

NotificationManagerService继承SystemService,是系统级别的service.

NotificationManagerService在init初始化的时候会加载/data/system/notification_policy.xml中的通知信息到内存数据结构,该文件中保存所有package注册的所有NotificationChannel。如下内容为xml文件部分内容。可以看到不同package下创建的channel以及channel相关属性。

</package>
<package name="com.android.providers.downloads" show_badge="true" uid="1010013">
<channel id="active" name="下载中" importance="2" sound="content://settings/system/notification_sound" usage="5" content_type="4" flags="0" show_badge="true" />
<channel id="complete" name="下载完成" importance="2" sound="content://settings/system/notification_sound" usage="5" content_type="4" flags="0" show_badge="true" />
<channel id="waiting" name="等待中" importance="2" sound="content://settings/system/notification_sound" usage="5" content_type="4" flags="0" show_badge="true" />
<channel id="insufficient_space" name="空间不足" importance="2" sound="content://settings/system/notification_sound" usage="5" content_type="4" flags="0" show_badge="true" />
</package>
<package name="com.android.providers.downloads" show_badge="true" uid="10013">
<channel id="active" name="下载中" importance="2" sound="
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值