Fetching User’s Last Known Location
Explore how to fetch the user's last known location in an Android app by managing runtime location permissions and using the FusedLocationProviderClient. Understand how to declare necessary permissions, request them, and retrieve location data safely after permission checks, preparing you for more advanced location tracking.
For this lesson, let’s assume that the user’s location access falls under dangerous permissions. The app needs to request location permissions before explicitly accessing the GPS location.
Let’s learn how to fetch the device’s last known location using the
LocationServices API.
Add the library dependency
We need to set up Google Play Services to access the device’s GPS location. Add the following library dependency in the app/build.gradle file:
Declare permissions in the manifest
We need to declare the following ...