android - 未在Notification.Builder中定义内部版本

标签 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());

在 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);

关于android - 未在Notification.Builder中定义内部版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26706739/

相关文章:

actionscript-3 - Flash CS6错误1120 : Access of undefined property (AS3)

java - 使用 “new double”时发生编译时间错误

android - 不能将调试器与 NotificationListenerService 一起使用

android-notifications - 带有 “null” PendingIntent的通知

android - 大通知图标的大小是多少?

java - 如何在Android Project中查找低版本上使用过的所有危险权限

java - 保存 boolean 值并在 Activity 中使用它

android - 未登录时是否可以获取公共(public) facebook 墙提要?

java - 无法创建广播接收器android

java - 需要修复的Infix程序的后缀