Skip to content

Getting Started

Terminal window
bun add @capgo/capacitor-accelerometer
bunx cap sync
import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

Get the most recent accelerometer sample that was recorded by the native layer.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';
await CapacitorAccelerometer.getMeasurement();

Check if the current device includes an accelerometer sensor.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';
await CapacitorAccelerometer.isAvailable();

Begin streaming accelerometer updates to the JavaScript layer.

Call with the measurement event to receive the updates.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';
await CapacitorAccelerometer.startMeasurementUpdates();

Stop streaming accelerometer updates started via .

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';
await CapacitorAccelerometer.stopMeasurementUpdates();

Return the current permission state for accessing motion data.

On platforms without explicit permissions this resolves to granted.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';
await CapacitorAccelerometer.checkPermissions();

Request permission to access motion data if supported by the platform.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';
await CapacitorAccelerometer.requestPermissions();

Alias for the most recent measurement.

export type GetMeasurementResult = Measurement;

Result returned by .

export interface IsAvailableResult {
/**
* Whether an accelerometer sensor is available on the device.
*
* @since 1.0.0
*/
isAvailable: boolean;
}

Permission information returned by and .

export interface PermissionStatus {
/**
* The permission state for accessing motion data on the current platform.
*
* @since 1.0.0
*/
accelerometer: AccelerometerPermissionState;
}

Event payload emitted when is active.

export type MeasurementEvent = Measurement;

The x, y and z axis acceleration values reported by the device motion sensors.

export interface Measurement {
/**
* The acceleration on the x-axis in G's.
*
* @since 1.0.0
*/
x: number;
/**
* The acceleration on the y-axis in G's.
*
* @since 1.0.0
*/
y: number;
/**
* The acceleration on the z-axis in G's.
*
* @since 1.0.0
*/
z: number;
}

Permission state union including limited for platforms that can throttle motion access.

export type AccelerometerPermissionState = PermissionState | 'limited';

Platform permission states supported by Capacitor.

export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';

This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.

If you are using Getting Started to plan dashboard and API operations, connect it with Using @capgo/capacitor-accelerometer for the native capability in Using @capgo/capacitor-accelerometer, API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, API Keys for the implementation detail in API Keys, and Devices for the implementation detail in Devices.