Skip to content

joostfunkekupper/background-location-sample-ktx

Repository files navigation

Location Tracking Example

The question "how do we do location tracking even when the app is in the background?" comes up frequently. This example application covers how to set up your permissions and using appropriate services to continuously get location updates.

Requirements

  1. JAVA 11 - Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
  2. Android SDK Platform 31
  3. Emulator running Android 12

Description

This application uses the Fused Location Provider API to get the devices location. By providing a PendingIntent the API will broadcast an Intent every time a location update is ready, which can be received via a BroadcastReceiver. Each location update is then stored in a Room database so that we can update the update the UI accordingly.

The app will attempt to request the necessary permissions each time we start the application, or show an error message to the user. Firstly, we request location foreground permissions, then we request location background permissions (aka "Allow all the time").

Android 12 has a greater focus on highlighting how apps are accessing private data, in our case location updates. A new feature care Privacy Dashboard in the device settings will show when apps are accessing such data. The app provides a rationale screen which explains why we are collecting location updates, which can be launched from the Privacy Dashboard.

Lastly, we may know what data we are accessing, but we may not know what third-party libraries are accessing. Using the AppOpsManager we can audit data access and capture/log that information. This doesn't necessarily add anything useful for end users, but will provide further insights for developers.

Main screen

References

Third-party libraries

(Excluding Android/Google libraries)

About

No description, website, or topics provided.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages