【问题标题】:Missing PendingIntent mutability flag giving warning after checking sdk version检查 sdk 版本后缺少 PendingIntent 可变性标志给出警告
【发布时间】:2022-01-10 12:32:52
【问题描述】:

嘿,我收到关于未决意图的警告。所以我根据这个question和这个medium帖子包围了检查sdk。我收到警告信息 缺少 PendingIntent 可变性标志

val pendingIntent: PendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
            } else {
                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
            }

如何删除此警告消息?

【问题讨论】:

  • 这看起来像是 Lint 检查中的一个错误,因为您的代码似乎没问题。
  • @CommonsWare 是的,我不明白为什么会发出警告:(
  • @vivekmodi 你能找出原因吗?我正在使用 WorkManger 2.7.1 版

标签: android kotlin android-pendingintent


【解决方案1】:

像这样添加待处理的意图

val updatedPendingIntent = PendingIntent.getActivity(
applicationContext,
NOTIFICATION_REQUEST_CODE,
updatedIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT )

如果错误仍然存​​在并且您的 targetSdkVersion = 31 则错误一定是由于您的依赖项之一在内部使用 WorkManager 或您直接使用旧版本的 WorkManager。 要解决只需添加此依赖项

implementation 'androidx.work:work-runtime-ktx:2.7.0'

【讨论】:

  • 我已经在我的项目中添加了这个库。
猜你喜欢
  • 2021-07-06
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
  • 2018-07-23
  • 2019-05-16
相关资源
最近更新 更多