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();   
  • 相关阅读:
    使用客户端模型编程处理外部列表
    在 SharePoint2010 中使用 XML 查看器取得其他站点的内容列表
    在 SharePoint2010 中编程方式使用 BCS
    使用 zip 压缩包手动安装 Orchard
    NuGet Action Plan 更新到 1.1, 设置自动更新,获取 NuGet 包浏览器
    Percentage Closer Filtering
    Direct3D轮回:游戏特效之全屏泛光(Bloom)
    高斯模糊
    Shadow Map
    像素级动态模糊(Pixel Motion Blur)
  • 原文地址:https://www.cnblogs.com/dongweiq/p/5525929.html
Copyright © 2011-2022 走看看