Я внедряю геозоны в своем приложении Android, и, хотя оно работает отлично, когда приложение находится на переднем плане или фоне, для получателя требуется около 5 минут, чтобы получить данные, если приложение прекращено. PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
private val jobSitesGeoFencePendingIntent by lazy {
val intent = Intent(context, JobSitesGeofenceBroadcastReceiver::class.java)
PendingIntent.getBroadcast(
context, 100, intent,
flag
)
}
reciever
class JobSitesGeofenceBroadcastReceiver : DaggerBroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent) // Dagger initialization happens here
val geoFencingEvent = GeofencingEvent.fromIntent(intent)
if (geoFencingEvent.hasError()) {
val errorCode = geoFencingEvent.errorCode
Timber.e("Geofence error: $errorCode") // Using Timber for logging
return
}
// ... (Geofence transition handling logic - ENTER/EXIT) ...
Timber.d("Geofence transition detected: ${geoFencingEvent.geofenceTransition}")
// NotificationUtil.notify(...)
}
}
manifest
Подробнее здесь: https://stackoverflow.com/questions/797 ... terminated