Android API 31 - WorkManager - PendingIntent - 标记 IMMUTABLE 错误

标签 android android-pendingintent flags android-workmanager

异常(exception) :
定位 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

最佳答案

基于 this bug ,似乎解决方法是添加对 androidx.core:core:1.7.0-alpha01 的依赖其中包括对 BuildCompat.isAtLeastS() 的修复.

It looks like what you are missing is a dependency on the latest version of android.core. That includes this change which has an important bug fix for BuildCompat.isAtLeastS().

关于Android API 31 - WorkManager - PendingIntent - 标记 IMMUTABLE 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68546589/

相关文章:

android - 隐藏 chrome 上的移动浏览器地址栏(android)

android - 如何更改 SmallTopAppBar、CenterAlignedTopAppBar、MediumTopAppBar 和 LargeTopAppBar 的背景颜色

css - 在 Chrome 29+ 中使用 CSS 变量

c# - 如何获得复杂的枚举值字符串表示

android - 如何获取存储在mysql中的经纬度并在android中的谷歌地图上显示

java - 如何在动画完成后自动将用户从(Lottie)启动动画转换到 MainActivity?

Android - PendingIntent 不调用 onCreate

Android:从小部件打开错误的 Activity

android - Intent 返回错误的数据

汇编语言 - 标志设置让我头疼