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. HDFS 搭建记录

    1. 三台服务: 172.17.0.62(namenode) 172.17.0.68(datanode) 172.17.0.76(datanode) /etc/hosts包含的内容: 三台都包含的域名 ...

  2. js 时间函数 及相关运算大全

    js 时间函数 及相关运算大全 var myDate = new Date(); myDate.getYear();        //获取当前年份(2位) myDate.getFullYear(); ...

  3. 从零开始学习MySQL3---数据库的基本操作

    创建数据库 MySQL安装完成后,将会在其Data目录下自动创建几个必需的数据库 可以用  SHOW DATABASES: 来查看当前存在的数据库 创建数据库是在系统磁盘上划分一块区域用于数据的存储和 ...

  4. [BZOJ 1500] [NOI2005] 维修数列

    题目链接:BZOJ - 1500 题目分析 我要先说一下,这道题我写了一晚上,然后Debug了一整个白天..........再一次被自己的蒟蒻程度震惊= = 这道题是传说中的Splay维护数列的Bos ...

  5. Asterix and Obelix

    uva10246:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...

  6. 转载百度百科上的强回复,关于spring的IOC和DI

    IoC与DI   首先想说说IoC(Inversion of Control,控制倒转).这是spring的核心,贯穿始终.所谓IoC,对于spring框架来说,就是由spring来负责控制对象的生命 ...

  7. SCP和SFTP(都使用SSH。但SCP上传不能中断,而SFTP可以续传,这是最大区别)

    不管SCP还是SFTP,都是SSH的功能之一.都是使用SSH协议来传输文件的. 不用说文件内容,就是登录时的用户信息都是经过SSH加密后才传输的,所以说SCP和SFTP实现了安全的文件传输. SCP和 ...

  8. pl/sql 关于变量定义的问题

    1. create or replace procedure  test_prc(p_data_dt in date) IS e_name emp.ename%type;      begin sel ...

  9. Service Trace Viewer Tool (SvcTraceViewer.exe)

    Service Trace Viewer Tool <?xml version="1.0" encoding="utf-8" ?> <conf ...

  10. Candies(差分约束)

    http://poj.org/problem?id=3159 题意: flymouse是幼稚园班上的班长,一天老师给小朋友们买了一堆的糖果,由flymouse来分发,在班上,flymouse和snoo ...