Đây là mã của tôi:Tại sao Eclipse không nhận ra phương thức build() từ lớp Notification.Builder để trả về một đối tượng Notification?
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);
Nó hoạt động tìm kiếm, nhưng sử dụng Notification notification = builder.getNotification();
bị phản đối. như tôi nên làm Notification notification = builder.build();
. Vấn đề là Eclipse không nhận ra nó như vậy, có nghĩa là nó sẽ không cho phép tôi biên dịch. Các tài liệu rõ ràng là build()
tồn tại và phương pháp ưa thích của nó, nhưng nó không hoạt động trên đầu của tôi. Tôi muốn sử dụng mã không được dùng nữa, vì vậy mọi trợ giúp sẽ được đánh giá cao.
nhập khẩu
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;
Hãy nhận biết rằng import android.app.Notification.Builder;
đang nói nó không được sử dụng.
Vâng thưa bạn. Tôi vừa cập nhật – Andy
Bạn có đang nhắm mục tiêu API 16 không? 'build()' là mới trong Jelly Bean. – Eric
Bạn đang sử dụng API nào? – Sam