Capture motion in Android apps

Forward app-observed Android shakes and accelerometer samples into an Ansight session.

Motion capture is opt-in. The ai.ansight:ansight-android aggregate includes ansight-motion-android; a core-only integration can add the motion artifact separately. Ansight does not register a SensorEventListener or request sensor permissions. Keep sensor ownership and lifecycle in your app.

Enable capture

Configure motion when initializing the development build from your Application:

import ai.ansight.Ansight

val options = Ansight.developerOptions(clientName = "Android App") {
    withMotionCapture()
}
Ansight.initializeAndActivate(application = this, options = options)

Forward observations

Call the motion facade from your existing shake detector or accelerometer listener:

import ai.ansight.motion.AnsightMotion
import android.hardware.SensorEvent

fun onShakeDetected() {
    AnsightMotion.recordShake()
}

fun onAccelerometerSample(event: SensorEvent) {
    AnsightMotion.recordAccelerometer(
        event.values[0].toDouble(),
        event.values[1].toDouble(),
        event.values[2].toDouble(),
    )
}

Android accelerometer SensorEvent values are already in metres per second squared. withMotionCapture() enables shakes and samples by default. Pass AnsightMotionCaptureOptions to disable either type or change minimumSampleIntervalMilliseconds; the interval defaults to 20 ms and is clamped to 10–1000 ms. Calls while the runtime is inactive or capture is disabled are ignored.

The host stores app-observed motion in motion/events.json and the session’s motion timeline. For emulator-injected input and the shared evidence contract, see Motion Capture.