Search code examples
androidandroid-fusedlocation

How to produce LocationRequest resolution dialog and catch onActivityResult callback in Service


So im using the FusedLocationApi to get the users location. Im also using the LocationRequest object to check if a location source is available and if not, ask the user for permission to turn on GPS(WiFi seems not to work on Lollipop devices). Now when the user clicks yes(or no), onActivityResult is called. My problem is, i have a Service that does nothing but tracks the users location, but i cannot use the LocationRequest object for resolution in the Service(which is precisely what i need) because Service doesnt have an onActivityResult method. Any tips on how to get around this?


Solution

  • Obvious answer was to launch this dialog in the Activity before starting the Service, then calling startService() in onAcivityResult, or if no resolution is required.