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

时间:2018-07-27 07:57:04

标签: android intentservice android-geofence android-jobscheduler

我正在开发一个应用程序,其中我必须实现一项功能,当用户输入特定范围或具有特定半径的位置时(例如在Geofence中)。然后,它应该发送也在客户端应用程序(不是FCM)中的通知。我尝试了多种解决方案,但无法正常工作。从Android O开始。后台任务限制。如何在没有Foreground的情况下实现此功能,否则看起来很烦人?请如果有人有任何想法请回复。提前致谢。

客户代码

geofencingClient.addGeofences( geoFencingReq(location!!.latitude,location.longitude,name), geofencePendingIntent)

待定意图->

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)
    }

我更新了我使用的代码,但是当应用被杀死时,它仍然无法正常工作。

1 个答案:

答案 0 :(得分:-1)

通过在Google API中注册Geofence,它们也会自动从后台调用。您可以在com.google.android.gms.location中找到它。

GeofencingClient.addGeofences(GeofencingRequest, PendingIntent)是您所需要的。

相关问题