简体   繁体   English

当应用不在前台或被杀死时,如何使地理围栏工作?

[英]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.

相关问题 应用被杀死后,Geofence无法正常工作 - Geofence doesn't work when the app is killed 即使应用被杀死,如何继续接收地理围栏通知? - How to receive continuous geofence notifications even when app is killed? Android - 当应用程序被杀时Geofence消失 - Android - Geofence disappearing when app is killed 应用在Android Oreo上被杀死时的地理围栏 - Geofence when app is killed on Android Oreo 当应用程序被杀死时,AlarmManager 在前台服务中不起作用 - AlarmManager does not work in foreground service, when app was killed 如何创建在应用程序被杀死/在后台时用户退出地理围栏时触发的BroadcastReceiver? - How to create a BroadcastReceiver that is triggered when a user exits a Geofence whilst the app is killed/in the background? 屏幕关闭时前台应用程序被杀死 - Foreground app being killed when screen is off 如何在应用程序被杀死时让 WorkManager 活着? - How to make WorkManager alive when app is killed? 使onDataChange仅在应用程序位于前台(打开且可见)时才起作用? - Make onDataChange work only when app is in the foreground (open and visible)? 当应用程序从前台被杀死时在 Ionic 应用程序中显示通知 - Showing Notifications in Ionic App when the app is killed from foreground
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM