Track Users Location in the Background with Android and Xamarin.Forms

preview_player
Показать описание
Learn how to track a users or device location in the background on Android. Using Xamarin.Forms and Essentials, we will see how to implement a foreground service on Android that tracks the users location even when the app is in the background, killed or even when the device is restarted!

💝 Join this channel to get access to perks:

Disclaimer: this channel is done on personal title, in my free time, and not officially affiliated with or endorsed by Microsoft (my employer) in any way. Opinions and views are my own.

🔗 Links

⏱ Timestamps
00:00 - Track Users Location with Android
00:11 - Android Background and Foreground Servic
02:56 - Let's Start Coding!
04:07 - Add Android Permissions
05:25 - Using Xamarin.Forms MessagingCenter
06:14 - Implement MessagingCenter Messages
07:30 - Implement Location Tracking Logic
10:30 - Implement NotificationHelper
15:43 - Implement Android Foreground Service
20:23 - Implement Android MainActivity Bootstrap
24:07 - Enable/Disable Background Service Functi
29:38 - See the Code in Action! Demo Time!
32:25 - Start Service on Device Start
38:47 - Do This Easier with Shiny.NET!
39:33 - Does this work with .NET MAUI?

🙋‍♂️ Also find my...

#location #background #xamarinforms #locationtracking #android
Рекомендации по теме
Комментарии
Автор

Thank you Gerald for your great work as always. Just a note for the mandatory API TARGET 33: - You need to add "POSTNOTIFICATION" on the android mainfest and change the to (or Mutable) otherwise a runtime error is generated.

mpini
Автор

Hi, thank you for this great video. I tried it on my actual phone but I experienced issues when my phone screen was off for more than a couple of minutes. Do you maybe know of any workaround that wouldn't stop tracking even if my screen is off?

mczaar
Автор

Hi Gerald, the application is working fine when it is in foreground, it is updating longitude and latitude but when application is in background after a while it stops to update longitude, latitude and timestamp. It is giving the readings but old one as application is back in foreground it works again. I am facing this problem on Android only, iOS is working fine.

burhanmunir
Автор

Great video for developers wanting to use their phone's location in the background. It's always good to know how it works rather than just using a library. FYI Penguin unicorns.

AnneAccount-nh
Автор

1:15 I love what you're saying right now because from what I understand there is a whole thing on my system that's being run through the way of foreground sinks and I am never asked if it's okay with me or not like ever, therefore learning what I just learned made my day better thank you

GoldzenJuLz
Автор

You are a lifesaver thank you!! Been struggling lately with this issues. How long till you make a tutorial about shiny? It goes some steps even further and the samples are pretty generic.

thanasissideridis
Автор

Hi Gerald - trying to implement this on MAUI. AndroidLocationService is derived from "Service" - can't find this in MAUI. Which using do I miss ?

weggetor
Автор

Primeiramente Parabéns pelo trabalho, se puder ajudar, no android 12 e 13 não está funcionando e tambem não montra nenhum tipo de erro, sabe dizer o que pode estar acontecendo?
Tradutor
First congratulations for the work, if you can help, in android 12 and 13 it is not working and also does not show any type of error, do you know what could be happening?

rodrigojacinto
Автор

Thanks for this video, regardless of fact that I’ve already solved this kinda problem this video gives it another angle. Thank you 😊

Ndydyamaka_r
Автор

Penguin unicorn. Thanks for the vid. Really well presented. I am an absolute newby android programmer and have foolishly decided my first attempt will be ambitious - to monitor whether dog has escaped putting phone on their collar. For this I need a geofence alert but the fence must be a polygon, not a circle. Maybe a good topic for a tutorial? Couldn't find any examples.

philb
Автор

Thanks for this video! Without this, I don't think I would have been able to do GPS tracking in my app. I appreciate that you copy-pasted from your provided github repo, so the video doesn't have to be as long and you can focus on the bigger picture concepts.

bandanaboii
Автор

Thank you, great video. I've alread implemented it, but you clarified me the architecture under the hood, and gave me some very good suggestion. And, yes, I'm one of the PenguinUnicorn!

MarcoGhizzi
Автор

Thank you. This is among the most productive minutes I have ever spent watching youtube. I copied your code and used it for a service other than location tracking. However, the service keeps on running even when the user closes the underlying app by swiping away from recent list. How to make the service stop when the app is killed? Also, is there any other way for the shared code to communicate with the service other than messenging center?

Tendertofu
Автор

Hey Gerald, again, great video and really helpful. It is soo smooth that penguins unicorns can slide through it. Keep it up!

ilijakocev
Автор

Thanks for doing this I had to figure it out myself how to implement this and it was a massive headache hopefully others won't have to suffer now

ZainSharaf
Автор

Penguin Unicorn. Thanks, Gerald for this video just what I need to add this functionality into my app, can't thank you enough. Thanks for the videos and content you produce.

leedonohue
Автор

Thank you very much!
This is exactly what I have been looking for.
Been stuck on this (foreground services in general, with and without locations) for the last 2 months, and most "solutions" out there don't work on Xamarin.Forms, or they crash the main thread.
Thank you!
lol penguin unicorns... I would like to see some tutorials on Shiny, I have heard good things about it.

Donald.Archer
Автор

That's three Udemy courses in one video. Thank you so much.

obaidniazi
Автор

Thanks for this video! I have one issue though, which is that some devices will kill the app / the service after some time when device goes into sleep mode.
Is there a workaround for this? Please help.

VirajChandra
Автор

Bro you are a life saver thank you. Could you do a tutorial on having a app that displays a webview and also overrides the hardware back button to go back in the webview and not exit the app?

tainebambrough