【发布时间】:2012-07-07 03:35:45
【问题描述】:
这是我的代码:
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; 表示它没有被使用。
【问题讨论】:
-
您的目标是 API 16 吗?
build()是果冻豆的新成员。 -
哈哈,不是JellyBean。集成电路。如果您不介意回答与此问题无关的快速问题,请附带说明。 ICS 中的大多数 API 是否都适用于 JellyBean。我问是因为我想升级到新的操作系统并尝试一下,但如果我的开发手机不支持我正在构建我的应用程序的话。
-
任何不在 Jelly Bean 中的 ICS 中的 API 只会被弃用,因此它们在 API 16 中仍然可以安全使用。但我会在升级之前在 4.1 模拟器上运行您的应用程序你的设备……以防万一。
标签: android eclipse deprecated notificationmanager