HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
57 stars 66 forks source link

Plugin reports as "isRunning=false", cannot get logs to debug #185

Open kevinmcody opened 7 months ago

kevinmcody commented 7 months ago

Describe the bug After I call the start() method, a subsequent call to checkStatus returns: authorization:1 hasPermissions:true isRunning:false locationServicesEnabled:true

I then tried to get log entries, using the getLogEntries method, and received the following error: code: 1003, message: 'Getting logs failed', cause: Value INFO at 1 of type java.lang.String cannot be converted to int

To Reproduce Steps to reproduce the behavior:

  1. window.BackgroundGeolocation.start();
  2. select the "while using app" option for authorization
  3. window.BackgroundGeolocation.checkStatus(function(state){ debugger; });
  4. See unexpected state.isRunning
  5. paste the log printing functions from https://haylltd.github.io/cordova-background-geolocation-plugin/debugging.html
  6. BackgroundGeolocation.getLogEntries(100, BackgroundGeolocation.LOG_INFO, printAndroidLogs);

Expected behavior I would expect isRunning: to be true. I would also expect getLogEntries to not throw an error

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

HarelM commented 7 months ago

Are you "awaiting" the promise when calling start?

kevinmcody commented 7 months ago

window.BackgroundGeolocation.start().then(result => { debugger; window.BackgroundGeolocation.checkStatus(function (state) { debugger; }); });

At the first debugger; result = "OK" At the second, state.isRunning = false

Bphreaker commented 5 months ago

Hello @HarelM,

Do you have any update on the issue?

I'm facing the exact same issue

HarelM commented 5 months ago

I don't know how to reproduce this. I would advise to attach a debugger and see what went wrong...

Bphreaker commented 5 months ago

Hello @HarelM,

I think I've found the problem.

We are migrating all the plugins and code to be compatible with Android 14 and MABS 10.

One of the changes we did, was changing the Android Target SDK to 34. By doing this the application stopped running in the background and it was returning the value IsRunning=false.

I've downgraded the target SDK version to 33 and it solve the issue. The value IsRunning=true and the notification is shown on the phone tray.

By investigating a little bit more on the issue I come to the conclusion that the plugin is not prepared to handle the ACCESS_BACKGROUND_LOCATION permission if the app is pointing to SDK 34.

Is it possible to include the option to access the location "All the Time"?

You have all it's needed in this link: https://developer.android.com/develop/sensors-and-location/location/permissions#background-dialog-target-sdk-version

HarelM commented 5 months ago

See my comments here:

HarelM commented 5 months ago

There might be a different bug related to sdk 34, but I would like to avoid adding this permission and I'm hoping this permission is not required for sdk 34. But feel free to investigate. I haven't yet moved my app to sdk 34, so that can explain why I haven't seen this issue.

Bphreaker commented 5 months ago

For now Google, Android SDK 33 is the required version if we want to submit a new build to the stores.

I think in the end of the year 2024 we will need to move to SDK 34 and do the upgrade on the code.

HarelM commented 5 months ago

If all that's missing is the permission, then you can do it now, externally, as I wrote in the linked issue. I hope there's a different solution to this issue though.

fulldiver-drc commented 1 month ago

Is the plugin being upgraded to target Android SDK 34 again? I've just started using this and I also noticed that status.isRunning is always FALSE even after a start() call.

And I'm not sure, but I think this is also affecting the stop() function. The success and failure handlers for the stop promise aren't being called, and I'm guessing this has something to do with it.

Which version can I use that still targets 33?

HarelM commented 1 month ago

I personally am not using isRunning but I do use it with SDK 34, so if this is something that you need fixed please investigate and open a PR. Thanks!