[英]how to make geofence work when app is not in foreground or it is killed?
I am working on an app where i have to implement a feature that when user enters a particular range or location with particular radius like in Geofence. 我正在开发一个应用程序,其中必须实现一项功能,当用户输入特定范围或具有特定半径的位置时(例如在Geofence中)。 Then it should send notification which is also in client app not FCM.
然后,它应该发送也在客户端应用程序(不是FCM)中的通知。 I have tried multiple solution but its not working.
我尝试了多种解决方案,但无法正常工作。 since Android O .
从Android O开始。 Background task limitation.
后台任务限制。 How to implement this feature without Foreground otherwise it would seem annoying?
如何在没有Foreground的情况下实现此功能,否则看起来很烦人? Please If anyone have any idea Do reply.
请如果有人有任何想法请回复。 Thanks in Advance.
提前致谢。
Code for Client 客户代码
geofencingClient.addGeofences( geoFencingReq(location!!.latitude,location.longitude,name), geofencePendingIntent)
Pending Intent -> 待定意图->
val geofencePendingIntent: PendingIntent by lazy {
val intent = Intent(contextt, GeofenceTransitionsIntentService::class.java)
// We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
// addGeofences() and removeGeofences().
PendingIntent.getService(contextt, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
I have updated the code which i have used but it doesnt work still when app is killed. 我已经更新了我使用的代码,但是当应用被杀死时,它仍然无法正常工作。
By registering the Geofence with the Google API they automatically also get called from the background. 通过使用Google API注册Geofence,它们也会自动从后台调用。 You can find it in
com.google.android.gms.location
. 您可以在
com.google.android.gms.location
找到它。
GeofencingClient.addGeofences(GeofencingRequest, PendingIntent)
is what you need. 您需要
GeofencingClient.addGeofences(GeofencingRequest, PendingIntent)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.