4

我在使用 NotificationCompat v7 和 Android O 时遇到问题。由于 NotificationCompatV7 的实现只实现了 v4 版本的已弃用构造函数(在支持库 26.0.0-beta1 中已弃用),因此我无法让通知工作。

此处提出了 NotificationCompat v4 的解决方案: NotificationCompat with API 26

但由于 v7 版本(https://issuetracker.google.com/issues/62475846)的实施不佳存在这个问题,我无法在 Android O 上发布通知

有没有人对此有解决方案,或者我在这里遗漏了什么?

4

1 回答 1

9

NotificationCompat v7 现在已弃用,您应该使用NotificationCompat v4(根据 NotificationCompat v7 class 的评论)。

/**
 * @deprecated Use the static classes in {@link android.support.v4.app.NotificationCompat}.
 */

然后你可以构建你的通知(Kotlin):

val notificationBuilder = NotificationCompat.Builder(context, "your_notification_channel_name")                     
.setContentTitle("title")
[...]

注:最新支持版本为“com.android.support:appcompat-v7:26.0.0”

于 2017-07-24T23:02:11.033 回答