Android app图标显示未读消息数

参考:http://dev.xiaomi.com/doc/p=3904/index.html

MIUI 6上重新设计了桌面app图标的角标显示,基本规则如下:

基本介绍


  • 默认的情况

当app 向通知栏发送了一条通知 (通知不带进度条并且用户可以删除的),那么桌面app icon角标就会显示1.此时app显示的角标数是和通知栏里app发送的通知数对应的,即向通知栏发送了多少通知就会显示多少角标。

  • 通知可以定义角标数

例如 有5封未读邮件,通知栏里只会显示一条通知,但是想让角标显示5. 可以在发通知时加个标示。

实现代码

第三方app需要用反射来调用,参考代码:

NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this) .setContentTitle(“title”).setContentText(“text”).setSmallIcon(R.drawable.icon); Notification notification = builder.build(); try { Field field = notification.getClass().getDeclaredField(“extraNotification”); Object extraNotification = field.get(notification); Method method = extraNotification.getClass().getDeclaredMethod(“setMessageCount”, int.class); method.invoke(extraNotification, mCount); } catch (Exception e) { e.printStackTrace(); } mNotificationManager.notify(0,notification);

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

显示角标工具类

=======

注意:示例源代码中MIUI系统的功能实现和官方介绍的方法不一样

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值