Closed JackMcKew closed 1 year ago
You are providing BackgroundGeolocation Config in your issue description.
this is the background-fetch plug-in. You need to provide background-fetch Config.
Plugin version: 4.11.4
This is not even a valid version of background-fetch. That’s a background-geolocation version.
Your error has nothing at all to do with background-geolocation. Your error is coming from background-fetch. I suggest you review the Background Fetch Headless Setup here.
https://github.com/transistorsoft/capacitor-background-fetch/blob/master/CHANGELOG.md
My apologies, I've now updated the original issue with the relevant information for this repo
I think you've migrated your App from Cordova and failed to properly migrate your BackgroundFetchHeadlessTask.java
.
The package
still references cordova
.
package com.transistorsoft.cordova.backgroundfetch; // <-------- THIS IS WRONG
import android.content.Context;
import com.transistorsoft.tsbackgroundfetch.BackgroundFetch;
import com.transistorsoft.tsbackgroundfetch.BGTask;
import android.util.Log;
public class BackgroundFetchHeadlessTask implements HeadlessTask {
.
.
.
}
See API docs Config.enabledHeadless
Thank you!
We've disabled background fetch for now but seems this was likely the problem
Your Environment
Capacitor info (
npx cap doctor
)Installed Dependencies:
@capacitor/cli: 4.7.3 @capacitor/ios: 4.7.3 @capacitor/core: 4.7.3 @capacitor/android: 4.7.3
#ready
:com.transistorsoft.tsbackgroundfetch.BGTask.fireHeadlessEvent
Exception java.lang.RuntimeException: com.transistorsoft.tsbackgroundfetch.BGTask$Error: com.deckee.app.BackgroundFetchHeadlessTask at android.app.job.JobServiceEngine$JobHandler.handleMessage (JobServiceEngine.java:145) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:240) at android.os.Looper.loop (Looper.java:351) at android.app.ActivityThread.main (ActivityThread.java:8364) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1013) Caused by com.transistorsoft.tsbackgroundfetch.BGTask$Error: com.deckee.app.BackgroundFetchHeadlessTask at com.transistorsoft.tsbackgroundfetch.BGTask.fireHeadlessEvent (BGTask.java:231) at com.transistorsoft.tsbackgroundfetch.BGTask.onTimeout (BGTask.java:196) at com.transistorsoft.tsbackgroundfetch.FetchJobService.onStopJob (FetchJobService.java:50) at android.app.job.JobService$1.onStopJob (JobService.java:76) at android.app.job.JobServiceEngine$JobHandler.handleMessage (JobServiceEngine.java:141)
package com.deckee.app;
import com.transistorsoft.locationmanager.adapter.BackgroundGeolocation; import com.transistorsoft.locationmanager.adapter.TSConfig; import com.transistorsoft.locationmanager.config.TSNotification; import com.transistorsoft.locationmanager.event.HeadlessEvent; import com.transistorsoft.locationmanager.http.HttpResponse; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode;
/**
/* This plugin will continue to operate with the settings as initalised with in Javascript while the app is terminated As long as a headless event is subscribed, any further custom implementation can be done in response to events while terminated inside the onHeadlessTask function /
// Thread for one liner to get position https://github.com/transistorsoft/capacitor-background-geolocation/issues/31
public class BackgroundGeolocationHeadlessTask {
boolean onTheWater = false;
@Subscribe(threadMode = ThreadMode.MAIN) public void onHeadlessTask(HeadlessEvent event) { // Get a reference to the BackgroundGeolocation Android API. BackgroundGeolocation bgGeo = BackgroundGeolocation.getInstance( event.getContext() );
} }
package com.transistorsoft.cordova.backgroundfetch; import android.content.Context; import com.transistorsoft.tsbackgroundfetch.BackgroundFetch; import com.transistorsoft.tsbackgroundfetch.BGTask; import android.util.Log;
public class BackgroundFetchHeadlessTask implements HeadlessTask { @Override public void onFetch(Context context, BGTask task) { String taskId = task.getTaskId(); boolean isTimeout = task.getTimedOut(); if (isTimeout) { Log.d(BackgroundFetch.TAG, "My BackgroundFetchHeadlessTask TIMEOUT: " + taskId); BackgroundFetch.getInstance(context).finish(taskId); return; } Log.d(BackgroundFetch.TAG, "My BackgroundFetchHeadlessTask: onFetch: " + taskId); // Perform your work here....
}