capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
177 stars 54 forks source link

BACKGROUND LOCATION NOT WORKING AFTER 5 MINUTES #94

Closed ivinantony closed 1 year ago

ivinantony commented 1 year ago

Describe the bug i was testing the plugin and it works well in ios and in some android. i was testing in google pixel 5 and after 5 minutes there is no response from the plugin when app in background and the screen is locked. i tested multiple devices [samsung m13 and pixel 5] both have the same issue.When we unlock the device and open the app, all the locations that were not updated coming in the console too.

To Reproduce Steps to reproduce the behavior: open the app in google pixel r real or Samsung m13 device-> activate background geolocation-> put the app to background -> lock the screen.

Expected behavior it should sent the data even its locked.

Screenshots

Screenshot 2023-02-28 at 6 04 04 PM

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context i am optimized the battery using battery optimization plugin already. Warning IN ANDROID STUDIO

2023-02-28 18:01:52.898 11870-12369 MessageQueue io.ionic.starter W Handler (com.google.android.gms.common.api.internal.ListenerHolder$zaa) {934c5a0} sending message to a Handler on a dead thread java.lang.IllegalStateException: Handler (com.google.android.gms.common.api.internal.ListenerHolder$zaa) {934c5a0} sending message to a Handler on a dead thread at android.os.MessageQueue.enqueueMessage(MessageQueue.java:560) at android.os.Handler.enqueueMessage(Handler.java:778) at android.os.Handler.sendMessageAtTime(Handler.java:727) at android.os.Handler.sendMessageDelayed(Handler.java:697) at android.os.Handler.sendMessage(Handler.java:635) at com.google.android.gms.common.api.internal.ListenerHolder.notifyListener(Unknown Source:8) at com.google.android.gms.internal.location.zzat.onLocationResult(Unknown Source:7) at com.google.android.gms.location.zzv.dispatchTransaction(Unknown Source:25) at com.google.android.gms.internal.location.zzb.onTransact(Unknown Source:22) at android.os.Binder.execTransactInternal(Binder.java:1321)

diachedelic commented 1 year ago

Can you replace the handleOnPause method in BackgroundGeolocation.java with the following, and see if that solves the problem?

@Override
protected void handleOnPause() {
    if (service != null) {
        service.onActivityStopped();
        new Thread(() -> {
            try {
                Thread.sleep(1000);
                this.bridge.getWebView().dispatchWindowVisibilityChanged(View.VISIBLE);
            } catch (Exception ignore) {}
        }).start();
    }
    stoppedWithoutPermissions = !hasRequiredPermissions();
    super.handleOnPause();
}
ivinantony commented 1 year ago

@diachedelic it seems working fine after your code you sent me above. thanks alot. can you make a new version with this change asap?

diachedelic commented 1 year ago

Please test that this is fixed in v1.2.12.