journey.sensors

Version compatibility

  • journey.sensors was introduced in version 4.85.0 of the JourneyApps Runtime and version 22.4.1 of the JourneyApps Container.

  • Currently only supported on Android and iOS.

Returns information about the device's accelerometer, compass and orientation data.

Supported fields

getCapabilities()

To retrieve a device's supported sensor capabilities.

main.ts
var capabilities = await journey.sensors.getCapabilities();
view.accelerometer_supported = capabilities.accelerometerIsSupported;
view.compass_supported = capabilities.compassIsSupported;
view.orientation_supported = capabilities.orientationIsSupported;

accelerometer.read()

Returns accelerometer data captured at a specific point in time.

Acceleration values include the effect of gravity (9.81 m/s^2), so that when a device lies flat and facing up, x, y, and z values returned should be 0, 0, and 9.81.

Properties returned:

  • x: Number value

  • y: Number value

  • z: Number value

  • timestamp: Unix Timestamp when sample was taken

accelerometer.registerListener()

Listeners supply an onData callback which will be invoked with the data argument set to the same format as a read function call. The onError callback will be called on an error condition, if called, no subsequent onData callbacks are executed. The argument provided to the onError function is a string error message.

Listener options:

Currently the only option supported for all sensors is the sampling period in milliseconds.

Example:

compass.read()

Returns compass data captured at a specific point in time.

Properties returned:

  • magneticHeading: The heading in degrees from 0-359.99 at a single moment in time. (Number)

  • trueHeading: The heading relative to the geographic North Pole in degrees 0-359.99 at a single moment in time. A negative value indicates that the true heading can't be determined. (Number)

  • headingAccuracy: The deviation in degrees between the reported heading and the true heading. (Number)

  • timestamp: Unix Timestamp when sample was taken

compass.registerListener()

See accelerometer.registerListener()

orientation.read()

Returns the orientation of a device with angles measured along a specific reference frame. See here for good depictions of the angles.

Properties returned:

  • alpha: Number value

  • beta: Number value

  • gamma: Number value

  • timestamp: Unix Timestamp when sample was taken

orientation.registerListener()

See accelerometer.registerListener()

Example Code

The below example code shows a view that allows a user to read and start/stop watching accelerometer data. The returned data saved to LocalDB objects and is presented in tables.

Last updated