notification.setLatestEventInfo(context, title, message, pendingIntent);    在target为23时删除了该方法,我们应该使用build模式

低于API Level 11版本,也就是Android 2.3.3以下的系统中,setLatestEventInfo()函数是唯一的实现方法。

Intent  intent = new Intent(this,MainActivity);  
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);  
notification.setLatestEventInfo(context, title, message, pendingIntent);          
manager.notify(id, notification);  

高于API Level 11,低于API Level 16 (Android 4.1.2)版本的系统中,可使用Notification.Builder来构造函数。但要使用getNotification()来使notification实现。前面版本在notification中设置的Flags,icon等属性都已经无效,要在builder里面设置。

Notification.Builder builder = new Notification.Builder(context)  
            .setAutoCancel(true)  
            .setContentTitle("title")  
            .setContentText("describe")  
            .setContentIntent(pendingIntent)  
            .setSmallIcon(R.drawable.ic_launcher)  
            .setWhen(System.currentTimeMillis())  
            .setOngoing(true);  
notification=builder.getNotification();  

高于API Level 16的版本,就可以用Builder和build()函数来配套的方便使用notification了。

Notification notification = new Notification.Builder(context)    
         .setAutoCancel(true)    
         .setContentTitle("title")    
         .setContentText("describe")    
         .setContentIntent(pendingIntent)    
         .setSmallIcon(R.drawable.ic_launcher)    
         .setWhen(System.currentTimeMillis())    
         .build();   

notification.setLatestEventInfo(context, title, message, pendingIntent); undefined的更多相关文章

  1. Android Notification.setLatestEventInfo弃用和Notification.Builder用法

    今天在学习小米便签的源码的时候,至于源码的地址,http://m.blog.csdn.net/article/details?id=50544248 ,里面有好多github的开源项目,打开项目,报错 ...

  2. Android Notification setLatestEventInfo方法已废弃

    代替setLatestEventInfo的方法是用Notification.Builder创建Builder对象,通过该对象设置Notification相关属性. otification.Builde ...

  3. reportComplaints.js: Uncaught TypeError: Cannot read property 'message' of undefined

    vonic 中遇到这么个问题, 一直提示我未定义, 可是明明有定义 var tab={ message:{ number:'', title:'' } } var id= { template: '# ...

  4. Androidn Notification的使用,解决找不到setLatestEventInfo方法

    转自:http://blog.csdn.net/songyachao/article/details/51245370#comments 今天使用4.0.3使用 Notification notifi ...

  5. 【转】【Android】Android不同版本下Notification创建方法

    使用 new Notification(int icon, CharSequence tickerText, long when)构造函数时,Eclipse却提示:" The constru ...

  6. Android不同版本下Notification创建方法

    项目环境 Project Build Target:Android 6.0 问题: 使用 new Notification(int icon, CharSequence tickerText, lon ...

  7. Android下setLatestEventInfo警告、Handler警告、SimpleDateFormat警告

    正 文: 今天飘易在做Android 4.4.2下的APP开发时,使用了Notification下的setLatestEventInfo()方法时,Eclipse却提示:“ 不建议使用类型 Notif ...

  8. Android Notification如何显示表情?

    遇到这种分析用什么实现的,肯定要祭出大杀器Android Device Monitor(AS在Tools->Android)打开之后,选中连接的设备,然后点击小手机图标,即可导出UI层次图.咱们 ...

  9. [置顶] android之Notification版本兼容性问题

    首先先来创建一个notification提示 //概要 String tickerText = context.getResources().getText(R.string.app_name).to ...

随机推荐

  1. uboot 连接脚本分析

    一.脚本分析 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm ...

  2. HTML5峰会小记

    5259月228日,在大连理工的伯川图书馆举办了一次HTML5峰会,小记一下这次峰会的内容. 名为HTML5峰会,其本质就是一次各大赞助商的轮番登场,产品介绍间隙插播一下HTML5.但是并不影响这次峰 ...

  3. SendMail

    public ActionResult SendMail() { MailMessage mss = new MailMessage(); mss.From = new MailAddress(&qu ...

  4. Delphi中快捷键的使用

    CTRL+SHIFT+↑(↓) 在过程.函数.事件内部, 可跳跃到相应的过程.函数.事件的定义(在INTERFACE和IMPLEMENTATION之间来回切换)CTRL+J (弹出DELPHI语句提示 ...

  5. Java反射的理解

    反射的作用:   1.运行时检查类的结构 2.运行时更改类的字段值 3.调用类的方法   准备知识:   Class类:虚拟机为每一个对象保存的一份对象所属类的清单: static Class for ...

  6. 试试Navicat和Axere RP Pro吧

    感觉在作头作起和沟通方面,这些东东真是提高不好效率呢~~~ 由于敏感,只作载图.

  7. innodb_buffer_pool_instances and innodb_buffer_pool_size的关系

    把buffer pool 分成一个用户指定的单独的区域, 每个有它自己的LRU list和相关的数据结构, 降低竞争在并发内存读取和写操作. 这个选项只有当innodb_buffer_pool_siz ...

  8. 【CF】509E Pretty Song

    数学规律题,很容易计算的.以初始测试数据3为例.Str    Y I S V O W E L--------------------------Len    1  2 3 4  | 5 6 7  8Y ...

  9. 【转】MFC界面更新实现方法

    原文网址:http://www.cnblogs.com/skywatcher/p/3572311.html 1.更新窗口 即采用UpdateWindow()函数立即发送WM_PAINT消息更新整个窗口 ...

  10. java Spring使用配置文件读取jdbc.properties

    Spring使用配置文件读取jdbc.properties 在beans.xml中加入两个必须的bean [html]<bean id="propertyConfigurer" ...