Android学习笔记,Notification通知事件

Android的通知事件,可以在状态栏上面显示,滚动显示通知突然内容以及图标,可以设置在状态栏展开的时候,显示通知项的标题和内容,以及点击它所打开的应用程序。。。

 

 

NotificationManager,通过getSystemService(Context.NOTIFICATION_SERVICE);来获取系统的通知管理器

 

新建一个通知事件,Notification notification = new Notification(R.drawable.icon, “状态栏上滚动显示的标题”, System.currentTimeMillis());

其中第一参数为notification在状态栏上显示的图标,第二个为添加时状态栏上显示的标题,最后为通知事件添加的时间。

 

通过notification.flags参数设置通知事件的标志,如是属于“正在进行的”还是“通知”等,具体得看reference了,,,

notification.flags |= Notification.FLAG_ONGOING_EVENT;

 

设置状态栏展开时,通知事件的标题和内容,以及点击所打开的程序。

Intent intent = new Intent(mContext, NotificationCancelAll.class);

PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);

notification.setLatestEventInfo(mContext, "NotificationTitle", 

"Notification Content!", pendingIntent);

 

如果有需要可以,自己定义在状态展开时所显示的view

RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.notification_test);

notification.contentView = remoteView;

 

最后添加设置好的notification即可,其中R.string.app_name为这个通知事件的ID,为后面移除这个通知用的。

 

mNotifyManager.notify(R.string.app_name, notification);

 

移除:

notifyManager.cancel(R.string.app_name);

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值