zoukankan      html  css  js  c++  java
  • notification.setLatestEventInfo(context, title, message, pendingIntent); undefined

    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();   
  • 相关阅读:
    Office365激活(无需密钥,无需下载软件)
    java垃圾回收及其优化
    Kafka副本机制
    sdn的相关学习系列之一mininet的安装
    javascript day 02
    关于javaScript
    html-day06
    盒子模型
    html-day04
    html--笔记day03
  • 原文地址:https://www.cnblogs.com/dongweiq/p/5525929.html
Copyright © 2011-2022 走看看