博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Android】Notification
阅读量:4599 次
发布时间:2019-06-09

本文共 2739 字,大约阅读时间需要 9 分钟。

通知的代码:

1 NotificationManager mNotifiManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);2 Notification notification = new Notification(R.drawable.stat_sys_call_record,  "停止", System.currentTimeMillis());//停止显示在状态3 notification.flags = Notification.FLAG_AUTO_CANCEL;4 Intent intent = new Intent(Intent.ACTION_VIEW);5 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);6 7 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);//包装Intent  //下拉通知后显示,getString处表示的标题,而“Test”是小字正文8 notification.setLatestEventInfo(this, getString(R.string.app_name), "Test", pendingIntent);9 mNotifiManager.notify(620066, notification);

关于PendingIntent:

A description of an Intent and target action to perform with it. Instances of this class are created with ,; the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time.

By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: often, for example, the base Intent you supply will have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call  to remove it.

关于它的FLAG,官方文档上也有解释:

Constants
int Flag for use with , and : if the described PendingIntent already exists, the current one is canceled before generating a new one.
int Flag for use with , and : if the described PendingIntent does not already exist, then simply return null instead of creating it.
int Flag for use with , and : this PendingIntent can only be used once.
int Flag for use with , and : if the described PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent.

Android中默认对PendingIntent的创建(如通过PendingIntent.getActivity方式)会进行优化检测,默认的情况下,新创建的PendingIntent如果和原先的基本一样,那么就会使用原先的PendingIntent。(这时候可以使用这四个参数控制PendingIntent的创建)

转载于:https://www.cnblogs.com/lqminn/archive/2012/10/17/2727541.html

你可能感兴趣的文章
Wireless Network 并查集
查看>>
51nod 1019 逆序数
查看>>
20145202马超《JAVA》预备作业1
查看>>
云推送注意(MSDN链接)
查看>>
IDEA 生成 jar 包
查看>>
加减乘除混合版
查看>>
linux基础6-bash shell编程
查看>>
掌握这几种微服务模式助你成为更出色的工程师
查看>>
为什么很多语言选择在JVM上实现
查看>>
绘制dot 图
查看>>
CSS Reset CSS Framework
查看>>
如何用WinCC发送报警消息至微信
查看>>
LeetCode算法扫题系列19
查看>>
nginx获取经过层层代理后的客户端真实IP(使用正则匹配)
查看>>
YII实现dropDownList 联动事件
查看>>
搞定PHP面试 - 正则表达式知识点整理
查看>>
为什么JavaScript里面0.1+0.2 === 0.3是false
查看>>
freemarker 设置中文
查看>>
docker swarm集群搭建
查看>>
选择排序
查看>>