This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo Accelerometer
A library that provides access to the device's accelerometer sensor.
Accelerometer from expo-sensors provides access to the device accelerometer sensor(s) and associated listeners to respond to changes in acceleration in three-dimensional space, meaning any movement or vibration.
Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
API
import { Accelerometer } from 'expo-sensors';
Classes
Type: Class extends DeviceSensor<AccelerometerMeasurement>
A base class for subscribable sensors. The events emitted by this class are measurements
specified by the parameter type Measurement.
Accelerometer Methods
Subscribe for updates to the accelerometer.
EventSubscriptionA subscription that you can call remove() on when you would like to unsubscribe the listener.
Checks user's permissions for accessing sensor.
Promise<PermissionResponse>Returns boolean which signifies if sensor has any listeners registered.
booleanYou should always check the sensor availability before attempting to use it.
Returns whether the accelerometer is enabled on the device.
On mobile web, you must first invoke Accelerometer.requestPermissionsAsync() in a user interaction (i.e. touch event) before you can use this module.
If the status is not equal to granted then you should inform the end user that they may have to open settings.
On web this starts a timer and waits to see if an event is fired. This should predict if the iOS device has the device orientation API disabled in
Settings > Safari > Motion & Orientation Access. Some devices will also not fire if the site isn't hosted with HTTPS as DeviceMotion is now considered a secure API.
There is no formal API for detecting the status of DeviceMotion so this API can sometimes be unreliable on web.
Promise<boolean>A promise that resolves to a boolean denoting the availability of the accelerometer.
Deprecated: use subscription.remove() instead.
voidAsks the user to grant permissions for accessing sensor.
Promise<PermissionResponse>Interfaces
A subscription object that allows to conveniently remove an event listener from the emitter.
Types
Each of these keys represents the acceleration along that particular axis in g-force (measured in gs).
A g is a unit of gravitational force equal to that exerted by the earth’s gravitational field (9.81 m/s^2).
Literal type: union
Permission expiration time. Currently, all permissions are granted permanently.
Acceptable values are: 'never' | number