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

我有以下代码,其给我的“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);

https://stackoverflow.com/questions/26706739/

相关文章:

haskell - 应用函数两次编译错误Haskell

compiler-errors - opencl编译错误

maven - 执行失败 : 'control build' & Failed to execute

intellij-idea - IntelliJ : “java connot find symbo

haskell - 用所有字母字符Haskell替换字符串中的所有字符的函数

c#-4.0 - 为什么我的变量在分配时说未分配?

scala - 使用getOrElse连接两个映射时,类型不匹配编译器错误

compiler-errors - 针对别名声明的错误10500

compiler-errors - 编译示例Scalapack应用程序时出现问题

compiler-errors - 无法解决错误,VHDL,语法错误,但我看不到