如何解决“缺少 PendingIntent 可变性标志"android api 30+ 中的 lint 警告? [英] How to resolve "Missing PendingIntent mutability flag" lint warning in android api 30+?

查看:315
本文介绍了如何解决“缺少 PendingIntent 可变性标志"android api 30+ 中的 lint 警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我将目标 SDK 更新到 30 (Android R),我的 Missing PendingIntent 可变性标志 就会出现 lint 警告code>PendingIntent.FLAG_UPDATE_CURRENT 标志,当我想定义 PendingIntent 时.

As soon as I updated the target SDK to 30 (Android R), a lint warning Missing PendingIntent mutability flag appeared on my PendingIntent.FLAG_UPDATE_CURRENT flag when I want to define PendingIntent.

我应该如何在不影响应用功能的情况下处理这个 lint?

How should I handle this lint with no effect on the app functionality?

推荐答案

您可以将待处理的意图设置为

You can set your pending intent as

val updatedPendingIntent = PendingIntent.getActivity(
   applicationContext,
   NOTIFICATION_REQUEST_CODE,
   updatedIntent,
   PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag 
)

根据此处的文档:https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability

强烈考虑使用FLAG_IMMUTABLE,只有在以下情况下才使用FLAG_MUTABLE某些功能取决于 PendingIntent 是可变的,例如如果它需要与内嵌回复或气泡一起使用.

Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

相应地选择您的旗帜.

如果您想了解更多相关信息,我建议您在此处阅读这篇很棒的文章:https://medium.com/androiddevelopers/all-about-pendingintents-748c8eb8619

If you want to read more about this i would suggest that you read this great article here: https://medium.com/androiddevelopers/all-about-pendingintents-748c8eb8619

这篇关于如何解决“缺少 PendingIntent 可变性标志"android api 30+ 中的 lint 警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆