簡體   English   中英

當應用不在前台或被殺死時,如何使地理圍欄工作?

[英]how to make geofence work when app is not in foreground or it is killed?

我正在開發一個應用程序,其中必須實現一項功能,當用戶輸入特定范圍或具有特定半徑的位置時(例如在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)
    }

我已經更新了我使用的代碼,但是當應用被殺死時,它仍然無法正常工作。

通過使用Google API注冊Geofence,它們也會自動從后台調用。 您可以在com.google.android.gms.location找到它。

您需要GeofencingClient.addGeofences(GeofencingRequest, PendingIntent)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM