源码

首页 » 归档 » 源码 » 在Android O中不推荐使用NotificationCompat.Builde…

在Android O中不推荐使用NotificationCompat.Builde…


将我的项目升级到Android O后

buildToolsVersion "26.0.1"

Android Studio中的Lint显示以下通知构建器方法的已弃用警告:

new NotificationCompat.Builder(context)

问题是:Android开发人员更新了描述NotificationChannel的文档以支持Android O中的通知,并为我们提供了一个代码段,但使用了相同的弃用警告:

Notification notification = new Notification.Builder(MainActivity.this)
        .setContentTitle("New Message")
        .setContentText("You've received new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setChannelId(CHANNEL_ID)
        .build();  

Notifications Overview

我的问题:是否还有其他解决方案可用于构建通知,并且仍然支持Android O?

我找到的解决方案是将通道ID作为Notification.Builder构造函数中的参数传递.但是这种解决方案并不完全可以重复使用.

new Notification.Builder(MainActivity.this, "channel_id")
(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/zaiandroid-ozhongbutuijianshiyongnotificationcompat-builde.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9 月 19, 2019 at 09:42 上午

热评文章