未在Notification.Builder中定义构建

时间:2014-11-03 01:59:09

标签: android compiler-errors android-notifications

我有以下代码,并且它给了我' 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文件。它仍然给我错误。

2 个答案:

答案 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