Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法从Notification.builder转换为Notification_Android - Fatal编程技术网

Android 无法从Notification.builder转换为Notification

Android 无法从Notification.builder转换为Notification,android,Android,我在整个通知和NotificationCompat故事中遇到问题,我在使用API 11,我正在尝试向通知中添加Style(),如下代码: Notification noti = new Notification.Builder() .setContentTitle("5 New mails from " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_mail) .setLargeI

我在整个通知和NotificationCompat故事中遇到问题,我在使用API 11,我正在尝试向通知中添加Style(),如下代码:

  Notification noti = new Notification.Builder()
 .setContentTitle("5 New mails from " + sender.toString())
 .setContentText(subject)
 .setSmallIcon(R.drawable.new_mail)
 .setLargeIcon(aBitmap)
 .setStyle(new Notification.InboxStyle()
     .addLine(str1)
     .addLine(str2)
     .setContentTitle("")
     .setSummaryText("+3 more"))
 .build();

这是developer.android本身在网站上建议的extact代码,但当我将其粘贴到自己的代码中时,它表示无法从Notification.builder转换为Notification。因此,我尝试使用NotificationCompat,但似乎方法setStyle对于NotificationCompat是未定义的,或者至少我是这么说的,我有什么办法可以处理这个问题吗?或者是否有任何compability库支持API 11的Notification.setStyle()?谢谢

改用。无论项目的API级别如何,都可以调用
setStyle()
(当然,如果设备不支持样式,该部分将被忽略)


注意:您还缺少生成器构造函数中的
上下文
参数——这对于本机
Notification.Builder
NotificationCompat.Builder

“这是开发者在网站上建议的extact代码。”--不在
Notification.Builder
文档中,他们在
上下文中正确地传递给
Notification.Builder
构造函数。不,我在NotificationComapt.InboxStyle中的意思是,上下文不是我的重点,我的重点是为什么我没有这样的东西NotificationComapt.InboxStyle是的,正如我所说,我试过的,但是NotificationCompa.Builder没有setStyle()方法是的,它有。您必须提供
Compat
变体(
NotificationCompat.InboxStyle
),伙计,试试看,我有最新的v4支持库,我没有这种东西NotificationCompat。InboxStyle@user3694470你确定吗?我刚刚测试过它,它很好用。这就是我讨厌的问题,我的SDK是最新的,我甚至尝试过v13