[android nfc] onNewIntent 中 无法获取 tag, 或者 intent.extras 为空, 或者 intent.action 为空

在做android nfc 场景的时候, 大方向上有2种:

  • foreground 调度系统
  • enableReaderMode api

foreground 调度系统, 发现android12下无法获取tag信息, 经过排查, 原因如下

在 android12 中

PendingIntent.getActivity(this, 0, 
                new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
                PendingIntent.FLAG_MUTABLE)

注意使用 PendingIntent.FLAG_MUTABLE 模式

flags细节

  • FLAG_IMMUTABLE:表示PendingIntent中的Intent不能被将Intent传递给PendingIntent.send()的其他应用程序修改。应用总是可以使用FLAG_UPDATE_CURRENT来修改它自己的PendingIntent
    在Android 12之前,默认情况下,不带此标志创建的PendingIntent是可变的。
    在Android 6 (API 23) 之前的Android版本上,PendingIntent总是可变的。

  • FLAG_MUTABLE:表示PendingIntent中的Intent应允许应用程序通过合并PendingIntent.send()的Intent参数值来更新其内容。
    始终填写任何可变的PendingIntent的包装Intent的ComponentName。不这样做可能会导致安全漏洞!
    此标志是在Android 12中添加的。在Android 12之前,在没有FLAG_IMMUTABLE标志的情况下创建的任何PendingIntent都是隐式可变的

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值