【发布时间】:2018-04-27 02:13:21
【问题描述】:
我有这个代码 sn-p 用于我的本地通知在 Oreo 设备上工作。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME,
level);
manager.createNotificationChannel(channel);
}
在我的窗口桌面上这很好,没有问题。但是在我的 macbook 上,lint 抱怨 NotificationChannel 需要 SDK 26,而我的最小值是 21。但是,如果我将版本检查更改为
if (Build.VERSION.SDK_INT >= 26)
错误消失了。我试过重新启动 Android 工作室,清理/重建。没有任何效果。当我进行代码检查并使用建议的提示时,它会将 Version_Code 更改为 26。让它在我的 2 台机器上的行为不同但完全相同的代码有点困扰我。其他人以前见过这个问题吗?
compileSdkVersion = 26
buildToolsVersion = "26.0.2"
minSdkVersion = 21
targetSdkVersion = 26
【问题讨论】:
-
您是否设置了 targetSdkVersion 以及是否设置了它
-
与上述相同的问题,但您的 compileSdkVersion 需要为 at least 26 才能使用此字段。
-
我添加了我的 gradle 语句。它们在两台计算机上都相同,只有 mac 抱怨。
-
我重新安装了android studio,错误消失了。我认为版本号与它有关。它在 2.3.1 上。
标签: android android-studio android-8.0-oreo notification-channel