我有以下代码,并且它给了我' 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());
在清单文件中,minSdk为13,targetSdk为19.目录中没有lib文件夹,我创建了一个并在其中添加了android-support-v4.jar文件。它仍然给我错误。
答案 0 :(得分:1)
由于您的目标是API 19和min 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);
答案 1 :(得分:0)
将minSdkVersion更改为19.同时更改其属性以使用API级别19进行编译,它将起作用。使用至少具有minSdkVersion的AVD。我建议使用tragetVersion