Skip to main content
@capgo/capacitor-accelerometer Device APIs Open source

Accelerometer Capacitor plugin

Read device accelerometer for motion detection and orientation tracking

Install

bun add @capgo/capacitor-accelerometer bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-accelerometer
  • pnpm add @capgo/capacitor-accelerometer
  • yarn add @capgo/capacitor-accelerometer

Guide

How to use Accelerometer in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Accelerometer plugin preview QR code

Using @capgo/capacitor-accelerometer

Capacitor plugin contract for working with the device accelerometer.

Install

bun add @capgo/capacitor-accelerometer
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

API at a glance

Method Description
getMeasurement Get the most recent accelerometer sample that was recorded by the native layer.
isAvailable Check if the current device includes an accelerometer sensor.
startMeasurementUpdates Begin streaming accelerometer updates to the JavaScript layer.
stopMeasurementUpdates Stop streaming accelerometer updates started via .
checkPermissions Return the current permission state for accessing motion data.
requestPermissions Request permission to access motion data if supported by the platform.

Examples

getMeasurement()

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

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

const result = await CapacitorAccelerometer.getMeasurement();
console.log(result);

isAvailable()

Check if the current device includes an accelerometer sensor.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

const result = await CapacitorAccelerometer.isAvailable();
console.log(result);

startMeasurementUpdates()

Begin streaming accelerometer updates to the JavaScript layer.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

await CapacitorAccelerometer.startMeasurementUpdates();

stopMeasurementUpdates()

Stop streaming accelerometer updates started via .

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

await CapacitorAccelerometer.stopMeasurementUpdates();

checkPermissions()

Return the current permission state for accessing motion data.

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

const result = await CapacitorAccelerometer.checkPermissions();
console.log(result);

requestPermissions()

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

import { CapacitorAccelerometer } from '@capgo/capacitor-accelerometer';

const result = await CapacitorAccelerometer.requestPermissions();
console.log(result);

Listen to events

addListener returns a handle. Call handle.remove() when the screen unmounts, or CapacitorAccelerometer.removeAllListeners() to clear every listener.

Full reference

Keep going from Using @capgo/capacitor-accelerometer

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

FAQ

Accelerometer plugin FAQ

How do I install the Accelerometer plugin in a Capacitor app?

Run "bun add @capgo/capacitor-accelerometer" (or "npm install @capgo/capacitor-accelerometer"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-accelerometer" in your app code.

Does @capgo/capacitor-accelerometer work with React, Vue and Angular?

Yes. Accelerometer is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-accelerometer support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-accelerometer free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-accelerometer/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Accelerometer without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Accelerometer changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo