1 year ago
#57137
Ahmad Albatsh
FLAG_IMMUTABLE is causing wrong behaviour
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a 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.
I'm sending broadcast using pending intent and I had to use the "or" condition to use both flags to prevent the crashes. But the problem is using FLAG_IMMUTABLE gives default values in "onReceive" in the broadcast, while using FLAG_UPDATE_CURRENT gives the correct values (apart from the crash). Is there a way to handle this problem? or is there a way to use something else than pending intent
fun getPendingIntent(): PendingIntent{
if (this::_pendingIntent.isInitialized)
return _pendingIntent
val intent = Intent(this,
GeofenceBroadcastReceiver::class.java)
val flags: Int
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
} else {
flags = PendingIntent.FLAG_UPDATE_CURRENT
}
_pendingIntent = PendingIntent.getBroadcast(this, REQUEST_CODE,
intent, flags)
return _pendingIntent
}
BroadcastReceiver class:
class GeofenceBroadcastReceiver(): BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)
//here the value is null
val geofenceList = geofencingEvent.triggeringGeofences
for (geofence in geofenceList) {
Timber.d("GEOFENCE onReceive: " + geofence.requestId)
}
}
}
android
geofencing
android-geofence
fusedlocationproviderapi
0 Answers
Your Answer