【问题标题】:how to make geofence work when app is not in foreground or it is killed?当应用程序不在前台或被杀死时,如何使地理围栏工作?
【发布时间】:2018-07-27 07:57:03
【问题描述】:

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

客户代码

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

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

【问题讨论】:

    标签: android intentservice android-geofence android-jobscheduler


    【解决方案1】:

    通过使用 Google API 注册地理围栏,它们也会自动从后台调用。你可以在com.google.android.gms.location找到它。

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

    【讨论】:

    • 感谢您的回复。我会在检查此解决方案后回复您,谢谢,@AntonioVlasic
    • 我已经更新了我的问题并添加了代码。它不起作用。 @AntonioVlasic
    猜你喜欢
    • 2015-06-22
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多