Background Location Service

Location service that still running when the app is minimized, plus network auto syncronization.

Singularity Indonesia Singularity Indonesia

Dependency Setting

Add it in your root build.gradle at the end of repositories:

allprojects {
        repositories {
                maven { url '' }

Add the dependency

dependencies {
        implementation 'com.github.SingularityIndonesia:ForegroundGPSTracker:1.3.0'

Setting Up in Kotlin


Setting Up in Java


Setup Alien

If you are using alien technology such Xamarin/Unity, C++ and other non java platform, you can create a portal interaction using AlienPortal object. See


This library will automatically sync your data to network, the body request will be

  "data": "{\"altitude\":0.0,\"speedAccuracyMeterPerSec\":0.5,\"bearing\":0.0,\"latitude\":37.29547,\"accuracy\":11.256,\"updateTime\":1688681353248,\"speed\":0.0,\"longitude\":-121.1872217,\"verticalAccuracyMeters\":0.5}",
  "descriptor": "{\"userID\":\"85158.72113324582\",\"messagingToken\":\"Dummy Messaging Token\"}"


You need to request all these permission in order to make it works:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

Important :

Android not allowing you to request background location before you’ve granted foreground location. So the permission request should be done in 2 steps:

  • First step is request all foreground permissions
  • Second step, after foreground permission granted, you should ask for background permission.

Note :

  • You will need context such activity context or application context both are fine.
  • The service will push the data for you, A.k.a automatic network syncronization. All you need are just setting up the network configuration.
  • You can use java or kotlin, the syntax won’t have a lot different, you can contact me for more help.

Build AAR Libray

If you need the aar file, to build the library just run the in the project root directory.

Design and Developed by: Stefanus Ayudha

Feel free to askme any question and support.

Powered by: Singularity Indonesia

Singularity Indonesia


View Github