【发布时间】:2021-07-27 14:15:40
【问题描述】:
例外: 定位 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一
导致异常的代码: WorkManager.getInstance(context).createCancelPendingIntent(id)
build.gradle 选项:
compileSdkVersion 31
buildToolsVersion '30.0.3'(版本 31.0.0 出现错误:安装的构建工具修订版 31.0.0 已损坏。使用 SDK 管理器删除并重新安装)。
模拟器: API 31(使用 API S 一切正常)
依赖项:
// 工作管理器
实现“androidx.work:work-runtime-ktx:2.7.0-alpha05”
实现 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
我认为问题可能出在 BuildCompat.java 的这种方法中:
/**
* Checks if the device is running on a pre-release version of Android S or a release version of
* Android S or newer.
* <p>
* <strong>Note:</strong> When Android S is finalized for release, this method will be
* deprecated and all calls should be replaced with {@code Build.VERSION.SDK_INT >=
* Build.VERSION_CODES.S}.
*
* @return {@code true} if S APIs are available for use, {@code false} otherwise
*/
@ChecksSdkIntAtLeast(codename = "S")
public static boolean isAtLeastS() {
return VERSION.CODENAME.equals("S");
}
那是因为当我在模拟器上运行应用程序并记录我得到的版本名称时: 版本名称:REL
【问题讨论】:
标签: android android-pendingintent flags android-workmanager