我有以下代码,其给我的“build()未在Notification.Builder中定义”错误。
Notification.Builder notificationBuilder = new Notification.Builder(mApplicationContext)
.setContentIntent(pendingIntent)
.setContent(mContentView)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setAutoCancel(true);
// Send the notification
NotificationManager mNotificationManager = (NotificationManager) mParentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
在 list 文件中,minSdk为13,targetSdk为19。该目录没有lib文件夹,我创建了一个文件夹,并在其中添加了android-support-v4.jar文件。仍然给我错误。
最佳答案
由于您的目标是API 19和最小API 13(HC),因此需要使用NotificationCompat.Builder-尝试:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
mApplicationContext);
Notification notification = notificationBuilder.setContentIntent(pendingIntent)
.setContent(mContentView)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setAutoCancel(true).build();
// Send the notification
NotificationManager mNotificationManager = (NotificationManager) mParentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, notification);