Skip to main content

Usage

Initialize SsBackgroundGeolocation with your API endpoint and credentials, then start tracking.


Initialize and start tracking​

import com.ss.tslocationmanager.SsBackgroundGeolocation

val trackingSdk = SsBackgroundGeolocation(activity)
trackingSdk.setActivity(activity)

trackingSdk.initSDK(
baseUrl = baseUrl,
apiKey = apiKey,
username = username,
context = activity,
clientId = clientId
) { success, token, error ->
if (success) {
trackingSdk.startTracking(
onSuccess = { /* tracking started */ },
onError = { errorMessage -> /* handle error */ }
)
} else {
// handle init failure: error
}
}

Stop tracking​

trackingSdk.stopTracking(
onSuccess = { /* tracking stopped */ },
onError = { errorMessage -> /* handle error */ }
)

Query state​

trackingSdk.getState(
onResult = { isTracking, _ -> /* use isTracking */ },
onError = { error -> /* handle error */ }
)

Forward permission results and clean up​

override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
trackingSdk.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

override fun onDestroy() {
trackingSdk.destroy()
super.onDestroy()
}

See also: Get Started, Authentication.