2014-10-10 42 views
-1
public void onClick(View v) { 
     Intent notificationIntent = new Intent(this, MainActivity.class); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 1, 
       notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

     NotificationManager nm = (NotificationManager) this 
       .getSystemService(Context.NOTIFICATION_SERVICE); 

     Resources res = this.getResources(); 
     Notification.Builder builder = new Notification.Builder(this); 

     builder.setContentIntent(contentIntent) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setLargeIcon(
         BitmapFactory.decodeResource(res, 
           R.drawable.ic_launcher)).setTicker("helllo") 
       .setWhen(System.currentTimeMillis()).setAutoCancel(true) 
       .setContentTitle("Messge").setContentText("Messge22"); 
     Notification n = builder.build(); 

     nm.notify(5, n); 
    } 

我想利用這個代碼發送Notifcation在按鈕的點擊,但存在代碼來顯示它錯誤調用錯誤需要API級別11(目前最小爲8): android.app.Notification.Builder#setContentIntent我已成立項目API級別19,請幫我哪裏做錯了,請給我建議的解決方案的目標=機器人-19項目根據企業的性質,而我不得不代碼:如何顯示Notificaion在Android API級別19

<uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="19" /> 
+0

集安卓的minSdkVersion =「11」中的清單文件 – santalu 2014-10-10 07:01:23

回答

1

如果你的應用程序支持的API版本號爲Android,但可以使用NotificationCompat.Builder,可從Android Support library獲取。

Notification.Builder - 本課程增加了Android 3.0 Honeycomb [API 11]。因此,如果您需要支持較舊的SDK,則需要使用NotificationCompact

NotificationCompat.Builder - 該課程版本爲4 Support Library(兼容Android 1.6及更高版本)。

欲瞭解更多信息請訪問How exactly to use Notification.Builder

+0

OK Suppoe如果我們會設定分鐘SDK安卓的minSdkVersion =「11」,將所有設備吶工作? – user2794306 2014-10-10 07:04:59

+0

使用'NotificationCompact'爲舊版Android版本支持 – 2014-10-10 07:10:00

+0

我將使用請編輯我的代碼coz android:minSdkVersion =「11」正常工作,但我希望它在所有請編輯我的代碼 – user2794306 2014-10-10 07:11:32

相關問題