Android Notification 通知 简单使用
来源:互联网 发布:上古世纪精灵捏脸数据 编辑:程序博客网 时间:2024/05/21 11:13
人不应该一直怀念过去,要活在当下,所以我现在讲的这个Notification 的使用是在API16及以上的环境的,不兼容低版本
步骤开始:
1.我们先创建一个Notification ,看下面代码可以看出是使用的建造者模式,顺便给它设置三个基本属性,注意,没这三个基本属性它是活不了的
Notification notification = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher)//设置小图标 .setContentTitle("这是标题") .setContentText("这是内容") .build();
2.获取Notification管理器
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
3.然后用这个Notification管理器把Notification弹出去,那个0是id,用来标识这个Notification的。
notificationManager.notify(0, notification);
4.最后我们发现点击弹出来的Notification没反应,因为我们没让它干嘛,所以我决定让它跳转到一个Activity里。这时候我们不是给它一个Intent,而是一个PendingIntent,意思就是等待的Intent,随时候着的意思,PendingIntent对Intent进行了包装,相当于将Intent跟Context进行打包,也就是PendingIntent是自带Context的,这样的话,就算应用程序关闭了,也不影响PendingIntent的启动。
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,TestActivity.class), 0);notification.contentIntent = pendingIntent;或者在创建的时候这样设置.setContentIntent(pendingIntent)
5.我们可以给它设置了flag,让它被点击后自动清除。
notification.flags = Notification.FLAG_AUTO_CANCEL;或者在创建的时候这样设置.setAutoCancel(true)
1 0
- Android Notification 通知 简单使用
- Android Notification通知简单使用DEMO
- Android API- Notification(通知)的简单使用
- Android 使用Notification(通知)
- android Notification通知使用
- Android 简单 通知栏 Notification
- Notification(通知)的简单使用
- Android中通知(Notification)的简单使用
- Android---60---Notification 通知栏的简单使用
- android通知(Notification)的使用
- android Notification(通知) 的使用
- Android 通知 Notification 使用详情
- Android通知Notification的使用
- android 使用通知(Notification)
- Android Notification(一)使用通知
- Android中使用通知Notification
- Android 使用通知(Notification)
- Android通知(Notification)使用详解
- 初入Java测试员之路
- 如何看懂一个程序
- python 关于fork模块及getpid方法自我理解。
- 如何编写出更有保存价值和使用价值的程序?
- Android分析破解-秒脱360加固大法
- Android Notification 通知 简单使用
- Linux文件读写与缓存
- 学习编程的秘诀
- 赋值语句的返回值为永真?
- 程序员面试金典--面试27之有一个正整数,请找出其二进制表示中1的个数相同、且大小最接近的那两个数
- 威佐夫博弈
- 重写equals方法
- 自定义ArrayList集合
- 六道JS面试题