NativeScript / nativescript-geolocation

Geolocation plugin to use for getting current location, monitor movement, etc
Apache License 2.0
139 stars 77 forks source link

Demo app doesn't record/track location when app is suspended #250

Closed Aceman18 closed 4 years ago

Aceman18 commented 4 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

"nativescript": { "id": "org.nativescript.demo", "tns-ios": { "version": "6.1.0" }, "tns-android": { "version": "6.0.2" } }, "dependencies": { "nativescript-geolocation": "../src", "nativescript-theme-core": "^1.0.4", "nativescript-toast": "~2.0.0", "nativescript-unit-test-runner": "0.7.0", "tns-core-modules": "^6.0.0" }, "devDependencies": { "jasmine-core": "^2.5.2", "karma": "4.1.0", "karma-jasmine": "2.0.1", "karma-nativescript-launcher": "^0.4.0", "nativescript-css-loader": "~0.26.0", "nativescript-dev-webpack": "^1.0.0", "tns-platform-declarations": "^6.0.0", "tslint": "~5.11.0", "karma-webpack": "3.0.5", "typescript": "~3.4.5" },

Please, tell us how to recreate the issue in as much detail as possible.

Run the demo app and start background thread monitoring. Then press home (suspend the app) and change location. Location is only recorded when you re-enter the app.

I assume this is supposed to run location tracking in the background i.e. when the app is suspended. If so I cannot get this to work on both the emulator and device provided above. Location services stops running.

Is the demo app supporting background location tracking? If not how would this be achieved in Nativescript Angular on Android?

Is there any code involved?

Demo app of this repo

Basler182 commented 4 years ago

I have the same problem. The Demo App isnt able to track in the background.

Aceman18 commented 4 years ago

@Basler182 and anyone else who checks this out. I have found a solution based around using a foreground service. It is based on this NativeScript/NativeScript#6994

This issue has been solved but also contained a demo project. I have updated that demo project to NS6.

There was also a fix needed for the webpack.config.js file I added this below based on this answer: https://stackoverflow.com/a/57757216

Before: const appComponents = [ "tns-core-modules/ui/frame", "tns-core-modules/ui/frame/activity", ];

After: const appComponents = [ "tns-core-modules/ui/frame", "tns-core-modules/ui/frame/activity", resolve(__dirname, "./src/foreground-service.android") ];

Here is the updated demo project: ns6-updated-foreground-service.zip

snackmaster95 commented 4 years ago

@Aceman18

Wow great resolution! That is what I was looking for the wohle day. Unlucky I dont manage to get it work in my existing NS-VueJS project. Any advice you might could give me to help me out? Also I am wondering where the 'date second: 234235235' console log comes from? I couldnt find any console log in the typescript which would result into something like this. Looking forwards for your answer. Best Regards snackman95

Aceman18 commented 4 years ago

@snackmaster95 Hi, unfortunately I don't personally have any VueJS experience so I won't be able to help specifically there.

However this solution only adds javascript/typescript to the project, so as far as I know there shouldn't need to be anything Vue specific? The files that are changed are webpack.config.js, androidManifest.xml, app.component.ts (or the root of your app), references.d.ts (if you don't have this just add it) and then the foreground-service.android.ts. If I'm correct this can all be translated into VueJS compatible files, but like I said my experience is limited?

The "date second" console log is located in the items.component.ts file

snackmaster95 commented 4 years ago

Thanks for your effort! I guess those informations should help me fix it. I will read into it and try to migrate it. Have a nice day!