Geofence Android isn't working (IntentService isn't called)

╄→尐↘猪︶ㄣ 提交于 2019-12-06 12:30:47

Had the same issue. Since Android 8 background work is more limited. There is a new way of calling IntentService. Check out newest Android guidelines for implementing Geofence listener:

https://developer.android.com/training/location/geofencing

In short, you just need to use GeofencingClient for calling PendingIntent which contains IntentService.

private PendingIntent getGeofencePendingIntent() {
    // Reuse the PendingIntent if we already have it.
    if (mGeofencePendingIntent != null) {
        return mGeofencePendingIntent;
    }
    Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
    // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when
    // calling addGeofences() and removeGeofences().
    mGeofencePendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.
            FLAG_UPDATE_CURRENT);
    return mGeofencePendingIntent;
}

Use link provided above for full example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!