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();   
  • 相关阅读:
    CentOS下MySQL的彻底卸载
    cent 7.0 安装mysql
    centos 安装mysql Package: akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)
    使用注解配置SQL映射器
    bean
    转:最简日志打印规范
    快速搭建sonar代码质量管理平台
    (转)Where与Having的总结
    一个问题,日后会写为什么贴出来
    hive Tutorial
  • 原文地址:https://www.cnblogs.com/dongweiq/p/5525929.html
Copyright © 2011-2022 走看看