这是我的代码:
NotificationManager mNotificationManager = (NotificationManager) c.getSystemService(ns);
//Instantiate the notification
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification.Builder builder = new Notification.Builder(c)
.setTicker(tickerText)
.setWhen(when)
.setContentTitle("Test Notification")
.setContentText(arg1.getStringExtra("info"))
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true);
Notification notification = builder.getNotification();
mNotificationManager.notify(88, notification);
它可以找到,但Notification notification = builder.getNotification();
不推荐使用。正如我应该做的那样Notification notification = builder.build();
。问题是 Eclipse 没有这样识别它,这意味着它不会让我编译。该文档很清楚build()
存在并且它是首选方法,但它不适用于我的目的。我想使用非弃用的代码,所以任何帮助将不胜感激。
进口
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
请注意,这import android.app.Notification.Builder;
是说它没有被使用。