How to Track Your Users Location in the Background in Android - Android Studio Tutorial

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии •

  • @sahilkanabar8605
    @sahilkanabar8605 2 года назад +21

    How can I be so lucky I just had a project with background tracking and here it is by best teacher like him on youtube .❤

  • @lifebylazy
    @lifebylazy 2 года назад +25

    "To provide a streamlined experience for short-running foreground services, devices that run Android 12 or higher can delay the display of foreground service notifications by 10 seconds, with a few exceptions. This change gives short-lived tasks a chance to complete before their notifications appear." - Android Docs, if anyone was curious about that weird delay behavior

  • @muhammadirfanrajput8400
    @muhammadirfanrajput8400 2 года назад +45

    Android gives continuous pain by continuous changing android SDK

    • @ChrisAthanas
      @ChrisAthanas 2 года назад +2

      Its a constant clusterfuck for sure

    • @SEMPERFIDELIS7
      @SEMPERFIDELIS7 Год назад

      It sure is one hell of a shame!

  • @BapeRuLLZ
    @BapeRuLLZ 2 года назад +7

    I think we may be able to improve upon the DefaultLocationClient class by putting all the locationmanager checking methods and also the context extension function into usecase classes that are wrapped by interfaces and the DefaultLocationClient class would depend upon those. That way you could unit test the class better by providing different mock implementations for the interfaces so if you would want to write a test case that checks the output if for example the gps is enabled but the location is not, then that way you could easily do that. It might be overkill but I think every unit test in itself could seem like an overkill. Just my two cents.

  • @AnkitKumar-dd8fo
    @AnkitKumar-dd8fo Год назад +2

    Adding foregroundServiceType="location" in Manifest file is very crucial for foreground service to run even if app is closed in higher android version.

  • @maximooze3196
    @maximooze3196 2 года назад +1

    send(location), exactly how khabib said it. Thanks again @Philipp

  • @mukammart379
    @mukammart379 2 года назад +4

    Hello! Can we unit test for FusedLocationProviderClient using mock? or we have to write ui test for it?

  • @halvtysk
    @halvtysk 2 года назад +3

    Nice video, we have this setup in our app, albeit implemented before the introduction of flows.
    If you "take requests" for future videos, I would love to see your approach to handling automatic startup of these types of services when a BLE device is present. Our devices requires physical activation and for our app to be ready for this, we have to keep a sticky notification at all times which is ugly. There are workarounds to use "companion devices", but the support for proximity to BLE devices seems limited to the latter two (?) Android versions. It would be interesting to see how you would handle the "do stuff when in proximity"-approach for both newer Android devices as well as for older.

  • @EmanNollase
    @EmanNollase 2 года назад +2

    nice tutorial. qq, what is the difference between foreground service vs WorkerManager?

  • @rarespetrusamartean5433
    @rarespetrusamartean5433 Год назад

    Thanks man, I got really stumped by needing to declare the service type in the manifest. Everything else was flawless and worked but as soon as I closed the app, it would stop sending locations to my server, which frustrated me to no end to the point where I resorted to youtube. Thanks again, this has been very annoying.

  • @juansuarez5216
    @juansuarez5216 Год назад +2

    Congrats!! Really good tutorial, well explained and keeping it as simple as possible

  • @alirahimi7425
    @alirahimi7425 4 месяца назад

    fantastic, but u need to add high accuracy for update frequently with new numbers

  • @McIntoch666
    @McIntoch666 2 года назад +6

    Location not updated

  • @Giulyozz
    @Giulyozz 2 года назад +1

    hi philip, great video, I was wondering if you had any suggestion for using a default location listener instead of fused location, i need my app to work without play services, thanks

  • @chndraja
    @chndraja 2 года назад +1

    Hi Philip, I ran into a issue, where my foreground service is closed after sometime in some OEM. Any idea on how to solve this issue.

  • @jopadjr
    @jopadjr Год назад

    1.3K+...Thanks Philipp. Great tutorial !! Would you mind adding Google Map series in your premium course?

  • @Adam0001
    @Adam0001 2 года назад +1

    Thank you Philipp🔥
    Could you make a tutorial about How to observe new data in the backgroud and then fire a notificarion.
    BEST WISHES

  • @roshanpvarghese4280
    @roshanpvarghese4280 2 года назад +1

    Just wondering why you didn't go with Work manager's long running worker for this?

  • @siddharthp2061
    @siddharthp2061 7 месяцев назад

    Nice tutorial ! How are you handling requesting permissions from user ?

  • @exploringgodscountry
    @exploringgodscountry 5 месяцев назад

    You have the best RUclips channel for Android development for sure. However, I'm old school. I've programmed in a BUNCH of languages... Really a hardware guy though. I cannot wrap my head around Kotlin. Are you not doing any Java tutorials on location services? I honestly, really don't want to learn Kotlin. I don't see it's utility.

  • @KhadijaHameed-bx2mt
    @KhadijaHameed-bx2mt Год назад

    you r going to catch 100k soon :D i noticed it from the 2 days it add +100 on regular but today it +200 so soon 😃👏

  • @bleuforcedz6727
    @bleuforcedz6727 2 года назад +1

    Can u do tutorial on how to make a background service cant be killed by battery optimization?

  • @sercanyigit3292
    @sercanyigit3292 2 года назад +1

    Hi Philip what theme are you using ?

  • @erzhananarkulov9826
    @erzhananarkulov9826 2 года назад

    awesome! I would like to ask what if I want to share location with my backend and see other users location of my app. is it a good if you request to server every second to update location? How uber taxi app handle it, for example? Thanks

  • @Uz_Mobile_Developer
    @Uz_Mobile_Developer 2 года назад +2

    Pls can you make vedio about canvas and using 3d objects in android

  • @jansk598
    @jansk598 Год назад +1

    Hi,does the foreground service run also when device is locked and in sleep mode?

  • @elgracko
    @elgracko Год назад

    Oh, this worked perfectly, thanks!! you have no idea how much this helps!!
    I'm definetly buying you that coffee, right now|

  • @dgcov
    @dgcov 5 месяцев назад

    I'd be very interested for Philipp to try to replicate the tutorial a year after it was originally posted. So much has been deprecated and changed in the SDK that it no longer compiles.

  • @ChrisAthanas
    @ChrisAthanas 2 года назад +2

    Very nice and thorough explanation!

  • @fredericoamigo
    @fredericoamigo 8 месяцев назад

    Good video, and I'm one of your biggest fans, but unfortunately the user location updates really really slow. Also. Is this a bit too complex? Is there an easier way to do this?

  • @АзизбекАширалиев-щ6ъ
    @АзизбекАширалиев-щ6ъ 2 года назад +2

    miui kills the foreground service, if battery optimization is enabled and autorun is disabled, I restart the service using FCM, if the device has stopped sending data durin some time, this is not the best solution, but working one

    • @alirehman842
      @alirehman842 2 года назад

      How you check service is stopped for sending notification

  • @yugmewada4339
    @yugmewada4339 Год назад

    I am working on android kotlin food delivery project i have order tracking screen in which path will be drawn and customer can track the driver’s location application support is 6-12 than what will the best way to do above defined job? I have to send updated lat long to api to suggest me accordingly

  • @Cyber-lw1bi
    @Cyber-lw1bi 7 месяцев назад

    Hi cool video but how do i make it that the camera of the google map follows the user's GPS position?

  • @galihgaharditama7432
    @galihgaharditama7432 2 года назад +1

    Link github of the source code is wrong, can you update it? Thanks..

  • @abdullahtutun
    @abdullahtutun Год назад

    You haven't used the ACCESS_BACKGROUND_LOCATION permission in the project. Would this cause any issues when uploading the app to Google Play?

  • @chabbishreels1983
    @chabbishreels1983 2 года назад

    What a great video, helps A LOT in the beginning.

  • @omarhaddad980
    @omarhaddad980 Год назад

    I found that calling `stop()` before even attempting to start will cause a problem. The reason I'm sharing this is because I'm trying to implement a `restartLocationTracking()` feature. It's essentially a location tracking refresher that involves calling `stop()` and then `start()`. This feature is particularly important when developing a Hybrid cross-platform app using Ionic and Capacitor. Is there a way to check if the (location is being tracked) before we call `stop()`?

  • @rajeevthakur4916
    @rajeevthakur4916 10 месяцев назад

    I have tried you other videos also and done each step to replicate the same but still having the issue that the notification is easily removeable by just swiping. With the foreground service i want to show a persistent/static/non-removeable notification which includes the stop button to directly stop the foreground service from the notification. By this the user will not have to open the app and the app will not be running in the background when the user dont want it to. I have tried .setOngoing etc but still not solution. Waiting for you response ..........

  • @lihan7257
    @lihan7257 2 года назад

    How to learn your coding style , so beautiful.

  • @berkc5323
    @berkc5323 Год назад

    Why did you use launch { send() } instead of trySend()? Is it okay to launch a new coroutine every time that location callback triggers?

  • @aviksutar
    @aviksutar 2 года назад

    Can you make a tutorial on complex survey form using json. Mean to say that the form is dynamically created from server end json response with multiple different layouts like rating bar, editext, radiobutton, spinners

  • @Cyber-lw1bi
    @Cyber-lw1bi 7 месяцев назад

    Hello... Am I the only one with the problem that the gps location does not change? So if i try to set a virtual gps location in extended controls, the app will continue to print out the original location until the whole emulated smartphone has been restarted. And then again, only the one location that has been set before the device restart is continuously printed out...

  • @learner5439
    @learner5439 Год назад

    Thank you Philipp for this wonderful video.

  • @InputOutput-b2l
    @InputOutput-b2l 11 месяцев назад

    I know i m kinda late but what IDE did you use and what programming languages?

  • @SengKuz
    @SengKuz 2 года назад

    Nice video, Thank you for your source code. it has useful to my develop about show location.

  • @kiruthigat0152
    @kiruthigat0152 Год назад

    Hi philipp,Could you please upload a video on monitor geofence

  • @Internet_Ghost-GA
    @Internet_Ghost-GA Год назад +1

    in 4:41 the android studio gives me an error .
    FusedLocationProviderClient . it gives me red color on these line I don't know how to solve these I did exactly like you .

  • @panagiotisangelosisiris6315
    @panagiotisangelosisiris6315 Год назад

    Hi Phillip! Can I take the coordinates from this foreground service and print them also on screen, somehow?

  • @guixp2965
    @guixp2965 Месяц назад

    I love u bro, saved my life

  • @xITRicKsHooTzIx
    @xITRicKsHooTzIx 2 года назад +1

    Hi, another wish I would like to see is background push notifications. I always had problems with that and the implementation is getting harder from experience.
    Thanks!

    • @jeromet
      @jeromet 2 года назад

      Check out tutorial using Firebase!

  • @EmanNollase
    @EmanNollase 2 года назад

    Also can I make request a tutorial: would possible to make tutorial about swipetodismiss(compose) but the catch is will wait for the server result before it will dismiss or not?

  • @PrabhatPandey-jk6ur
    @PrabhatPandey-jk6ur Год назад

    Thank you brother, you made our life easy.

  • @onlinemarketing9865
    @onlinemarketing9865 2 года назад

    Sir,, Please help me.. I have faced a problem..
    My app previous update version was only 10
    megabyte. But now I have added some features,, the size jumped to 25 MB, which is not possible because I have added very small amount of code... When I cancled all and go to previous version by github using version control; it also showing 25MB in released version,,, which was 10MB..

  • @salmaK20012
    @salmaK20012 Год назад +1

    YOU ARE A LIFE SAVER!

  • @michaelremme8319
    @michaelremme8319 Год назад

    Really really great, what you did. It was exactly what i was searching for ( for nearly a week of search ). Transfer into java was not that complicated.
    I have one question: why are you building the NorificationChannel inside the Application? I found some others, which are building it inside the Service directly. In that way it seems that they are recreating it with each location update. Cause of this?

    • @RK-lv9qc
      @RK-lv9qc Год назад

      I dont think it's possible , for creating UI we need to request through mainactivity and we need to build a channel before our activity gets paused or destroyed , so we need to make use of application class , one other way is to use the Mainactivity and build the channel there

  • @faxmodem2397
    @faxmodem2397 Год назад

    Hello, how can we save this information and send it to the backend? And the second question is how can we send an alarm to the backend when the user turns off the GPS

  • @mustafaammar551
    @mustafaammar551 2 года назад

    Very cool video
    Thank You Bro
    Wish you all the best

  • @NazoFruciak
    @NazoFruciak 5 месяцев назад +1

    If for some reason your location doesnt update try with setting HIGH accuracy Priority in request:
    val request = LocationRequest.Builder(interval)
    .setPriority(Priority.PRIORITY_HIGH_ACCURACY)
    .setMinUpdateIntervalMillis(interval)
    .build()
    in my case it solved the problem.

  • @yaddogaming
    @yaddogaming 2 года назад

    How we can make a code editing app or a code compiler (with jetpack compose) , pls make a video on this 🙏

  • @JonuGurjar
    @JonuGurjar Год назад

    Hi Phillip, I was seeking the same solution but it's not working when app gets killed, can you please add something

  • @retechitsolution2564
    @retechitsolution2564 Год назад

    Thank its good prectice for me.
    But one my question How to send location on pho server

  • @dhiraj.20
    @dhiraj.20 2 года назад

    Nice tutorial, Thanks Philipp

  • @zlash7
    @zlash7 2 года назад

    The link below "Get the source code for this video here" is wrong

  • @DrakotMetal
    @DrakotMetal 2 года назад

    why don't you use IntentService? what you include in it runs on the background by default

  • @TidelxD
    @TidelxD 8 месяцев назад

    Thank You Philip you are the best

  • @skarloti
    @skarloti 2 года назад

    Beautiful and clear Thanks!

  • @juarez.roberto
    @juarez.roberto 2 года назад

    This video is gold !!

  • @pranjalisrivastava6170
    @pranjalisrivastava6170 Год назад

    How to play navigation sound when navigation started to confirm that voice directions are working in android studio?

  • @krepkovmeste
    @krepkovmeste 2 года назад

    It was very informative, but it's not entirely clear where all the code comes from ... I'm beginner in android dev, only know web development and everything is much simpler and clearer there
    It would be cool if a video appeared on RUclips on how to make a full-fledged gps tracker with sending the received data to the server in MySQL and authorization, or at least there were normal lessons that would teach you how to use the original source to master mobile development...

  • @babatundeadenowo7568
    @babatundeadenowo7568 4 месяца назад

    I have followed all of the process, but the location in the notification bar remains "Location: null" and doesn't update with the actual latitude and longitude. The only difference in my implementation is that I put the call to start the service in the setContent on the MainActivity, just before the NavHost, rather than onClick of a button. This is because I need my app to always track.

    • @adilansari-bm5vb
      @adilansari-bm5vb Месяц назад

      i also facing same issue how you fix this issue????

  • @omarhaddad980
    @omarhaddad980 Год назад

    at 08:40 I think there must be an OR instead of and AND in the line 24 where you check gps and network

    • @PhilippLackner
      @PhilippLackner  Год назад +1

      No, if one of these is enabled GPS can be used

    • @omarhaddad980
      @omarhaddad980 Год назад

      @@PhilippLackner Great video BTW, and now I get it, so the phone can get location using the network also besides the the Gps sensor itself, in this case I would rename the variable isNetworkEnabled to isNetworkLocationEnabled. but of course this is a personal preference. thanks a lot for the help

  • @ameentehseen6900
    @ameentehseen6900 2 года назад

    Finally ! thank you Philipp

  • @yugmewada4339
    @yugmewada4339 Год назад

    Why you have used flow? Why you cant used mutable live data of Location?

  • @vishwanathkumbar3083
    @vishwanathkumbar3083 2 года назад

    We have alternative solution for location tracking.we can use listenableworker and show notification

  • @avinashgupta4038
    @avinashgupta4038 Год назад

    the code not working, can you please make another video on this topic

  • @deepfuchsia7204
    @deepfuchsia7204 Год назад

    Hey Philipp, thanks for the video and the code. I had problems with foreground service and your code worked perfectly fine.
    I have an additional question tho.
    Let's say we want to render a map and a polyline which would render something like a path using the list of locations gathered over time.
    The map is rendered inside a @Composable. What's the best way to pass the location data from the service into the @Composable, so it can render the path?

    • @hegde421201
      @hegde421201 Год назад

      use arcgis polyline API

    • @berkc5323
      @berkc5323 Год назад

      did you find a nice way? I am actually trying to find a way to use the location in a Fragment. I need to pass it to something like a StateFlow and collect it in the Fragment.

  • @dalveersinghdaiya2844
    @dalveersinghdaiya2844 2 года назад +1

    Exceptional content

  • @additionalaccount4974
    @additionalaccount4974 Год назад

    everything is fine but the location is hella inaccurate.
    i need very precise location
    please help

  • @florianaleman9120
    @florianaleman9120 Год назад

    Hey great tutorial.
    I have some trouble getting the location in background idf i dont implement the code for the notifications. Is it possible ?

    • @sedraopamp
      @sedraopamp Год назад

      I've tested with different devices (Samsung S20, Motorola G42 and Pixel 6a), and LocationManager provides a location every 10 minutes in the background. I've not found an approach to reduce this time. However, you must add background location permission in the manifest and request it to the user. Coarse and Fine location will only work in foreground.

  • @ahmedelaswly1231
    @ahmedelaswly1231 Год назад

    Thank You , it was so clear

  • @ManishDubeyAndroid
    @ManishDubeyAndroid 2 года назад

    Can’t we extend LifecycleService and use lifecycleScope instead of creating own coroutineScope with supervisor?

  • @roshkaalex
    @roshkaalex Год назад +3

    Hi Philipp. What about ACCESS_BACKGROUND_LOCATION permission? Should we use this permission for tracking in background?

    • @NathanMeadeWSG
      @NathanMeadeWSG Год назад

      I had to. Also for Android 13 devices you will need to prompt the user to "Allow all the time" for the location permissions of the app.

    • @sedraopamp
      @sedraopamp Год назад

      Fine and coarse locations will only work in foreground since Android 11. Access_Background_Location is a must BUT these android versions reduce location updates to report them every 10 minutes in my tests with different manufacturers in the background.

    • @roshkaalex
      @roshkaalex Год назад

      @@sedraopamp we had the same results... i thought that this permission will resolve background tracking issues... but still we have empty zone on the map

    • @sedraopamp
      @sedraopamp Год назад

      @@roshkaalex You need also to disable battery optimization e.g. Samsung S20 stops the location manager if that feature is enabled, no matter if background location permission is allowed.

  • @Uz_Mobile_Developer
    @Uz_Mobile_Developer 2 года назад +1

    Thanks for usefull vedio.

  • @sahilkanabar8605
    @sahilkanabar8605 2 года назад

    can we track location after user take out our app through recent?

  • @jackc-gw7630
    @jackc-gw7630 9 месяцев назад

    Hey. The location doesnt seem to update continesly anymore?

  • @danishranjan9208
    @danishranjan9208 2 года назад

    it work on my pc thx bro vеry much

  • @RadhaVaddireddy
    @RadhaVaddireddy 2 года назад

    showing 'create(): LocationRequest' is deprecated. Deprecated in Java' message, please suggest how to resolve this issue.

  • @_WT_WhiteKnight7YT_
    @_WT_WhiteKnight7YT_ 2 года назад

    thank you so much dude you're a god

  • @raojilani3103
    @raojilani3103 Год назад

    thank you thank you so much for this help

  • @flowzk921
    @flowzk921 2 года назад

    Great Video!

  • @marvelrivera1194
    @marvelrivera1194 Год назад

    Phillip my location isn't changing.. just the same location on every update

    • @jackc-gw7630
      @jackc-gw7630 9 месяцев назад

      have you found a way to update location continuesly?

  • @EntertheBlackDragon
    @EntertheBlackDragon Год назад

    Column will not render, not sure what that's about.

  • @Tech1st
    @Tech1st 2 года назад

    can't we running after close the app?

  • @rithulraj3348
    @rithulraj3348 2 года назад

    Is it possible to track location when the app is killed?

  • @codefriendly8528
    @codefriendly8528 5 месяцев назад

    Is this work on android 14 as well?

  • @joaopaulopop
    @joaopaulopop Год назад

    Thank you very much!

  • @trevortrevose9124
    @trevortrevose9124 2 года назад

    Heard facebook tracks user search history and keystrokes is this possible or a myth

  • @GirishKumar-vj6yy
    @GirishKumar-vj6yy Год назад +1

    Thanks Bro😊

  • @cernaruka
    @cernaruka 11 месяцев назад

    Great, thanks a lot

  • @hasnainahmad8295
    @hasnainahmad8295 9 месяцев назад

    val request = LocationRequest.create()
    .setInterval(interval)
    .setFastestInterval(interval)
    stopForeground(true) --- deprecated
    Sir, create(), setInterval(), and setFastestInterval() methods are deprecated now. Plz guide for alternatives.

    • @jackc-gw7630
      @jackc-gw7630 9 месяцев назад

      have you found a way to update location continuesly?

    • @btryx9378
      @btryx9378 6 месяцев назад

      val request = LocationRequest.Builder(interval).build()