BirjuVachhani / locus-android

An Awesome Kotlin Location library to retrieve location merely in 3 lines of code
https://birju.dev/posts/retrieve-location-in-just-3-lines-android/
Apache License 2.0
358 stars 40 forks source link

I have a foreground service, how to Locus in that service #49

Closed yasirahmedkhan closed 3 years ago

yasirahmedkhan commented 3 years ago

I want to use locus in my foreground Service. Hello, I want to access location when my application is in background for this i have created a foreground service in my app, but im unable to use locus in foreground service as it is asking for instance of fragment, Kindly give me some sample code that how can i use this library if foreground service ?

BirjuVachhani commented 3 years ago

@yasirahmedkhan

You can use this method:

https://github.com/BirjuVachhani/locus-android/blob/b6c483d6ccf0f624a33f080d2d4519620780a74a/locus/src/main/java/com/birjuvachhani/locus/Locus.kt#L170

Please keep in mind that this only works with LifecycleService. So your service must extend it.

yasirahmedkhan commented 3 years ago

@yasirahmedkhan

You can use this method:

https://github.com/BirjuVachhani/locus-android/blob/b6c483d6ccf0f624a33f080d2d4519620780a74a/locus/src/main/java/com/birjuvachhani/locus/Locus.kt#L170

Please keep in mind that this only works with LifecycleService. So your service must extend it.

Thanks dear It is working now, but now another problem is coming when my app goes in background location updates stop working. What can be the possible issue ?

BirjuVachhani commented 3 years ago

@yasirahmedkhan You need to request background location permission I think.

Do this before starting location updates:

Locus.configure {
    enableBackgroundUpdates = true
}
BirjuVachhani commented 3 years ago

Feel free to reopen if you need any help.