• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Post Oreo Geofencing in background

marhab

Lurker
I have been looking at every tutorial, every piece of code I could find, and I am still failing to get geofencing to work on Android 8 and 9...
I am using as recommended by Google, an explicit Intent with a BroadcastReceiver, declared in the Manifest like this (custom intent?):

<receiver
android:name=".GeofenceBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.mypath.ACTION_RECEIVE_GEOFENCE"/>
</intent-filter>
</receiver>
I also declared (as recommended) a GeofenceTransitionsJobIntentService:
private static final int JOB_ID = 573;
private static final String TAG = "GeofenceTransitionJobIntentService";
private static final String CHANNEL_ID = "channel_01";

public static void enqueueWork(Context context, Intent intent) {
enqueueWork(context, GeofenceTransitionsJobIntentService.class, JOB_ID, intent);
}

// The JobIntentService will call this, even when the app is in the background
protected void onHandleWork(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent == null) return;
else { handleTheTransition(); }
}

Note the comment: // The JobIntentService will call this, even when the app is in the background
However, it NEVER works once the app is in the background.
The old way, using location tracking and computing if you are within a geofence still works, but stops after a while .

I have tried to download some tutorials and examples, but I haven't been able to get a single one to work.
I heard about JobService, or ForegroundService, but it would seem unnecessary for geofencing, which should work even if the app is in the background, in my view this is what geofencing is for :)

Have any of you had any luck with post Oreo background geofencing? I am sure I am doing something wrong, but I can't figure out what it is...
Thank you for any help or recommendations!!
 
Back
Top Bottom