【发布时间】:2021-12-05 10:58:27
【问题描述】:
PendingIntent 中一个新的 PendingIntent 字段是 FLAG_IMMUTABLE。
在 31 中,你必须指定 MUTABLE 或 IMMUTABLE,否则你不能创建 PendingIntent,(当然我们不能有默认值,那是给失败者的)参考here
根据(搞笑的)Google Javadoc for Pendingintent,您基本上应该始终使用 IMMUTABLE(empasis 我的):
强烈建议在创建 PendingIntent 时使用 FLAG_IMMUTABLE。 FLAG_MUTABLE 仅应在某些功能依赖于修改底层意图时使用,例如任何需要与内联回复或气泡一起使用的 PendingIntent(编辑评论:WHAT?)。
是的,所以我总是为这样的地理围栏创建 PendingIntents:
PendingIntent proximityIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_NO_CREATE)
一直运行良好。但是,按照上面的文档,我添加了这样的 IMMUTABLE 标志:
PendingIntent proximityIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_NO_CREATE|PendingIntent.FLAG_IMMUTABLE)
现在,结果是当我仍然在接收器中进行地理围栏转换时,如果我调用
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
它返回 null!
所以,我有两个问题。
-
为什么 IMMUTABLE 标志导致我没有像过去那样获得触发地理围栏?
-
我做错了吗?有没有办法使用地理围栏触发器设置 IMMUTABLE?
其实我有三个问题:
- 为什么 Google 的文档如此混乱、糟糕、矛盾和落后? (这是一个反问)
非常感谢指针。
【问题讨论】:
-
这就是人们不再在 Stack Overflow 上提问的原因。
标签: android android-pendingintent android-geofence android-12