Geofence Data is empty on transition
Asked Answered
I

1

5

I setup a geofence which gets triggered as expected, when the device exits the radius. However the geofencing event is completely empty.

override fun onReceive(context: Context, intent: Intent) {
    val geofencingEvent = GeofencingEvent.fromIntent(intent)
}
  • geofencingEvent.geofenceTransition is -1
  • geofencingEvent.triggeringGeofences is null
  • geofencingEvent.triggeringLocation is null
  • geofencingEvent.hasError() is false

Which is not very surprising, since the intent is empty as well. But where does e geofence-trigger intent usually get its data from to help GeofencingEvent.fromIntent() to build the event? What could go wrong, that the intent is empty? (no action, no extras... the intent uri looks like this :

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

I found this question from 7 years ago, which describes the same behavior without an answer. I followed this documentation pretty accuratley. Any ideas what I could be doing wrong?

Itching answered 22/1, 2022 at 7:49 Comment(0)
I
16

I found out that making the PendingIntent which is used when the geofence is triggered mutable fixes this issue!(On Devices with Android >11)

val geofencePendingIntent = PendingIntent.getBroadcast(
            context, 0, intent,
            PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
Itching answered 22/1, 2022 at 11:6 Comment(3)
Thanks for the answer. Before, I use FLAG_IMMUTABLE but it doesn't work.Calcicole
I struggled with that for some time, so thanks! This really should be added to the documentation.Leucite
above solution works. visit flybuy.com/android-12-pendingintent-mutability-and-geofences. this link might help.Fitly

© 2022 - 2024 — McMap. All rights reserved.