Nofication的使用
2016-05-15 15:30
295 查看
//获取NotificationManager对象
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)//
.setSmallIcon(R.drawable.ic_launcher)//设置显示的小图标
.setContentTitle("标题")//设置显示的标题
.setContentText("这是内容")//设置显示的内容
.setWhen(System.currentTimeMillis())//设置到达的时间
.setTicker("消息来了...");//设置第一次到达显示提示信息
Notification notification = builder.build();
//pendingIntent对象是个跳转Intent当用户点击通知提示栏时打开一个Activity
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,new Intent(MainActivity.this,MainActivity.class),0);
//设定下拉通知栏时显示的标题及内容信息
notification.setLatestEvenInfo(getApplicationContext(),"通知标题","这是个新的通知",pendingIntent);
//设定通知当用户单击后自动消失
notification.flags|=Notification.FLAG_AUTO_CANCEL;
//设定通知触发时的默认声音
notification.defaults|=Notification.DEFAULT_SOUND;
//通过管理器的notify方法发出通知
manager.notify(1, notification);
Notification的另一种创建方法
Notification notification = new Notification(R.drawable.icon,"我的通知",System.getcurrentTimeMillis());
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)//
.setSmallIcon(R.drawable.ic_launcher)//设置显示的小图标
.setContentTitle("标题")//设置显示的标题
.setContentText("这是内容")//设置显示的内容
.setWhen(System.currentTimeMillis())//设置到达的时间
.setTicker("消息来了...");//设置第一次到达显示提示信息
Notification notification = builder.build();
//pendingIntent对象是个跳转Intent当用户点击通知提示栏时打开一个Activity
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,new Intent(MainActivity.this,MainActivity.class),0);
//设定下拉通知栏时显示的标题及内容信息
notification.setLatestEvenInfo(getApplicationContext(),"通知标题","这是个新的通知",pendingIntent);
//设定通知当用户单击后自动消失
notification.flags|=Notification.FLAG_AUTO_CANCEL;
//设定通知触发时的默认声音
notification.defaults|=Notification.DEFAULT_SOUND;
//通过管理器的notify方法发出通知
manager.notify(1, notification);
Notification的另一种创建方法
Notification notification = new Notification(R.drawable.icon,"我的通知",System.getcurrentTimeMillis());
相关文章推荐
- ftrace kprobe调试
- 关于 @synchronized,这儿比你想知道的还要多
- PHP语言 -- Smarty函数
- Android实现Banner界面广告图片循环轮播(包括实现手动滑动循环)
- 关于Session的保存用户信息的用法。
- CSDN博客中使用超链接
- 自定义view 园环交替等待效果
- 229. Majority Element II 【M】【52】
- IOS小知识点总结
- Binder学习笔记(八)—— 客户端如何组织Test()请求 ?
- NSLock/NSRecursiveLock/NSConditionLock/@synchronized 详细解释
- JS(JavaScript)插入节点的方法appendChild与insertBefore
- 蓝桥杯:排序
- 239. Sliding Window Maximum
- Android开发,30行代码集成图片轮播RollViewpager,你说快吗?
- GridView中日期不显示时分秒的完美解决方法
- 封装类:即8种基本类型对应8种封装类
- iOS开发系列—Objective-C之Foundation框架
- C还可以这么玩第二期
- FromBottomToTop第十一周项目博客