-
-
Notifications
You must be signed in to change notification settings - Fork 76
Sample Background Service for the Angular version #263
Comments
Hey, I'm struggling with this as well but will share my code once I figure it out. I've tried the following solutions but each one has an error. 1. Angular Singleton service with RXJS timer.This works the best by far but has the hardest error. I have tested this solution on phisical Galaxy A8, A11, S8, J3. I use an RXJS loop and 2. Implement geolocation example background-service.If I use the default background-serivce.ts example in the demo, I can connect this to an angular service to turn it on. This works all fine using 3. Angular Singleton service with geolocation.watchLocation.This does not work, I can never seem to get the 4. Implement geolocation example background-service combined with RXJS timer.I did a hybrid implementation of the above method, where I use the manual What's Next?I'm determined to find a solution for this so I will keep investigating. I think the major issue here is location services are never triggering. I've seen some StackOverflow issues about this saying it's only related to Samsung devices but I cannot test this. One way I can get it to work with solution #1 is run navigation of maps in the background. I can see this triggers the location service always on, and my app will usually get a new location every 40 seconds when I'm going to attempt to fork the nativescript-geolocation plug and add in @OVERRIDES to kick start the location service before requestion a new location so it doesn't use google maps cache. |
nothing? |
I forgot to come back to this after posting sorry! I managed to get the outcome I needed using this plugin. I ran the plugin on its own Android FOREGROUND service with a notification and it works in the background, app minimized/background (not closed), screen off. Looks like the following:
I store the last known location on the foreground service. Then I can fetch it whenever I want from an Angular service. To start/trigger from an Angular service I do the following:
Then at the bottom:
Then I just fetch the location with an interval from my Angular service for whatever I need it for.
This is a short summarised version. If you are having trouble trying to implement a solution with a Foreground Service feel free to drop a question and I'll do my best to help out :) |
How were you able to get the location when the app is minimised in the foreground/background service? I try to use the plugin however the gps location doesn't change even though the gps is following a route. |
Make sure to check the demo app(s) for sample usage
I've checked, also all of the issues, but couldn't figure out how to create a background service in the NS Angular verions.
Make sure to check the existing issues in this repository
Done, found a couple of similar issues, with no final solution or didn't help
If the demo apps cannot help and there is no issue for your problem, tell us about it
Please, ensure your title is less than 63 characters long and starts with a capital
letter.
Which platform(s) does your issue occur on?
Android, Emulator, and Device both
Please, provide the following version numbers that your issue occurs with:
tns --version
to fetch it): 6.5.0node_modules/tns-core-modules/package.json
file in your project)"tns-android"
and"tns-ios"
properties in thepackage.json
file of your project)package.json
file of yourproject and paste your dependencies and devDependencies here)
Please, tell us how to recreate the issue in as much detail as possible.
Describe the steps to reproduce it.
Is there any code involved?
Tried to use this sample but doesn't work:
https://github.com/NativeScript/nativescript-geolocation/tree/master/demo/app
So it would be great a workable sample for an NS-Angular too.
My StackOverflow question:
https://stackoverflow.com/questions/62162963/how-to-implement-android-background-service-in-a-nativescript-angular-project
The text was updated successfully, but these errors were encountered: