【问题标题】:Geofence Data is empty on transition过渡时地理围栏数据为空
【发布时间】:2022-01-24 19:04:04
【问题描述】:

我设置了一个地理围栏,当设备退出半径时,它会按预期触发。然而,地理围栏事件是完全空的。

override fun onReceive(context: Context, intent: Intent) {
    val geofencingEvent = GeofencingEvent.fromIntent(intent)
}
  • geofencingEvent.geofenceTransition 为 -1
  • geofencingEvent.triggeringGeofences 为空
  • geofencingEvent.triggeringLocation 为空
  • geofencingEvent.hasError() 是假的

这并不奇怪,因为意图也是空的。但是地理围栏触发意图通常从哪里获取数据以帮助 GeofencingEvent.fromIntent() 构建事件?什么会出错,意图是空的? (没有动作,没有额外内容......意图 uri 看起来像这样:

intent:#Intent;launchFlags=0x10;component=de.yukiarts.test/.GeofenceBroadcastReceiver;end

我在 7 年前发现了这个 question,它描述了相同的行为而没有答案。我关注了这个documentation相当准确。有什么想法我可能做错了吗?

【问题讨论】:

    标签: android kotlin broadcastreceiver android-geofence


    【解决方案1】:

    我发现将触发地理围栏时使用的 PendingIntent 设置为可变可修复此问题!(在 Android >11 的设备上)

    val geofencePendingIntent = PendingIntent.getBroadcast(
                context, 0, intent,
                PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
    

    【讨论】:

    • 感谢您的回答。之前,我使用 FLAG_IMMUTABLE 但它不起作用。
    猜你喜欢
    • 2014-05-19
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多