Android Trip Detection¶

The SDK can detect vehicle movements and notify your app when a trip is detected.

NB: At the moment, only bicycle or car trips can be detected.

Before enabling trip detection, SafeRider must be initialized and the application needs to have been granted the ACTIVITY_RECOGNITION permission.

In order to be notified about trip detection events, you have to set a LRTripDetectionListener in your application’s onCreate().

Then to start listening to user movements call enableTripDetection().

class TestApplication : Application() {
    private val demoTripListener = object : LRTripDetectionListener {
        override fun onTripDetected(vehicleType: LRVehicleType) {
            Log.d(TAG, "onTripDetected: $vehicleType")
        }
    }

    override fun onCreate() {
        super.onCreate()
        SafeRider.initialize(
            context = applicationContext,
            apiKey = "apiKey",
        )
        // The trip listener should be set right after init.
        SafeRider.sharedInstance.tripListener = demoTripListener
        SafeRider.sharedInstance.enableTripDetection(LRVehicleType.BICYCLE)
    }
}