我在使用NotificationCompat v7和Android O时遇到了麻烦。 由于NotificationCompatV7的实现仅实现了v4版本的弃用构造函数(was deprecated in support library 26.0.0-beta1),因此无法使Notifications工作。
此处提出了NotificationCompat v4的解决方案: NotificationCompat with API 26
但是由于v7版本(https://issuetracker.google.com/issues/62475846)执行不佳存在此问题,我无法在Android O上发布通知
有人为此解决了问题,或者我在这里遗漏了什么?
答案 0 :(得分:9)
现在不推荐使用NotificationCompat v7,您应该使用 NotificationCompat v4 (根据NotificationCompat v7类的注释)。
/**
* @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”