在下面的代码中,Eclipse发现错误:
The method build() is undefined for the type NotificationCompat.Builder
在添加之前一切正常ActionBarSherlock http://actionbarsherlock.com/(下列的本教程 http://www.grokkingandroid.com/adding-actionbarsherlock-to-your-project/).
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
public class NotificationActivity extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int notifyID = 1;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.zcicon)
.setAutoCancel(true)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS)
.setTicker("mytitle").setContentTitle("mycontent")
.setContentText("text, text");
Intent resultIntent = new Intent(context, CalcareReader.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MyActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
nm.notify(notifyID, mBuilder.build()); // error here
}
}
build()
已添加到较新版本的 Android 支持包中。根据您获取和设置 ActionBarSherlock 的方式,您可能使用旧版本的 Android 支持包。确保您在 SDK Manager 中下载了最新版本,然后使用它android-support-v4.jar
在 ActionBarSherlock 项目和主应用程序项目中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)