<aside> 💡 Copy the “backgroundgeolocation” package from the example app to your android module: Link to Example App: https://github.com/manishbsta/background-geolocation
</aside>
<manifest ...>
// add these permissions
<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.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application ...>
<activity ...>
<intent-filter>
...
</intent-filter>
</activity>
// add the following service and broadcast receiver
<service
android:name=".backgroundgeolocation.LocationService"
android:foregroundServiceType="location" />
// broadcast receiver to be added
</application>
</manifest>
Register the new React Native Module like:
import com.<packagename>.backgroundgeolocation.BackgroundGeolocationPackage
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
...................................................
----->> add(BackgroundGeolocationPackage()) <<-----
...................................................
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
buildscript {
ext {
...
minSdkVersion = xx <<------------------------ change to 24
playServicesLocationVersion = "21.3.0" <<---- "21.3.0" // use latest
...
}
...
}
...
dependencies {
...
// add the following dependency
implementation("com.google.android.gms:play-services-location:21.3.0") // use latest
...
}
<aside> 💡 Copy the “background-geolocation” module from the example app’s “modules” directory to your project’s root path: Link to Example App: https://github.com/manishbsta/background-geolocation
</aside>