@capgo/capacitor-accelerometer

中文文档
8.0.55发布于 2026/11/09MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.2万

Read device accelerometer measurements with Capacitor

原始使用文档
文档目录22 节
  1. ➡️ Get started for free
  2. Key features
  3. Why Capacitor Accelerometer?
  4. Documentation
  5. Compatibility
  6. Install
  7. Configuration
  8. iOS
  9. Android
  10. API
  11. getMeasurement()
  12. isAvailable()
  13. startMeasurementUpdates()
  14. stopMeasurementUpdates()
  15. checkPermissions()
  16. requestPermissions()
  17. addListener('measurement', ...)
  18. removeAllListeners()
  19. getPluginVersion()
  20. Interfaces
  21. Type Aliases
  22. Credit

@capgo/capacitor-accelerometer

Read raw accelerometer data on iOS, Android and the web with one API, as the latest sample or as a live stream. Build motion features, games and gesture detection without paid plugins.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-accelerometer in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-accelerometer to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-accelerometer for Capacitor apps

Key features

  • Latest sample: getMeasurement() returns the latest cached x, y and z acceleration from Core Motion on iOS, SensorManager on Android and browser motion events on web. Before the first web motion event it returns zeros.
  • Live updates: startMeasurementUpdates() streams readings to the measurement listener until stopMeasurementUpdates().
  • Availability check: isAvailable() reports accelerometer availability on iOS and Android, and browser motion API support on web.
  • Permissions: checkPermissions() and requestPermissions() handle motion access where the platform requires it.
  • Platforms: iOS, Android and Web. iOS uses Core Motion, Android uses SensorManager, and web listens to browser motion events.

Why Capacitor Accelerometer?

The only free and maintained Capacitor plugin for accelerometer access. Other plugins are either paid or no longer updated. This plugin provides:

  • Up-to-date implementation - Uses the latest APIs across all platforms
  • Consistent JavaScript API - Same interface as popular paid alternatives
  • Cross-platform - Works on iOS, Android, and Web
  • Permission handling - Built-in permission management
  • Real-time streaming - Listen to continuous accelerometer updates

Perfect for fitness apps, games, gesture detection, and motion-based interfaces.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/accelerometer/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-accelerometer` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-accelerometer
npx cap sync

Configuration

iOS

Add the following to your app's Info.plist. iOS requires this key before the Motion & Fitness permission dialog can appear:

<key>NSMotionUsageDescription</key>
<string>We need access to motion data to read accelerometer measurements</string>

Then call requestPermissions() (or start measurement updates) to trigger the system prompt.

Android

No additional configuration is required. Android does not expose a dedicated runtime permission for raw accelerometer access on supported devices.

API

Capacitor plugin contract for working with the device accelerometer.

getMeasurement()

getMeasurement() => Promise<GetMeasurementResult>

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

Returns: Promise<Measurement>

Since: 1.0.0


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if the current device includes an accelerometer sensor.

Returns: Promise<IsAvailableResult>

Since: 1.0.0


startMeasurementUpdates()

startMeasurementUpdates() => Promise<void>

Begin streaming accelerometer updates to the JavaScript layer.

Call {@link addListener} with the measurement event to receive the updates.

Since: 1.0.0


stopMeasurementUpdates()

stopMeasurementUpdates() => Promise<void>

Stop streaming accelerometer updates started via {@link startMeasurementUpdates}.

Since: 1.0.0


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Return the current permission state for accessing motion data.

On platforms without explicit permissions this resolves to granted.

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

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

Returns: Promise<PermissionStatus>

Since: 1.0.0


addListener('measurement', ...)

addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>

Listen for measurement updates.

ParamTypeDescription
eventName'measurement'Only the measurement event is supported.
listenerFunc(event: Measurement) => voidCallback invoked with each measurement.

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners that have been registered on the plugin.

Since: 1.0.0


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Interfaces

Measurement

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

PropTypeDescriptionSince
xnumberThe acceleration on the x-axis in G's.1.0.0
ynumberThe acceleration on the y-axis in G's.1.0.0
znumberThe acceleration on the z-axis in G's.1.0.0

IsAvailableResult

Result returned by {@link CapacitorAccelerometerPlugin.isAvailable}.

PropTypeDescriptionSince
isAvailablebooleanWhether an accelerometer sensor is available on the device.1.0.0

PermissionStatus

Permission information returned by {@link CapacitorAccelerometerPlugin.checkPermissions} and {@link CapacitorAccelerometerPlugin.requestPermissions}.

PropTypeDescriptionSince
accelerometerAccelerometerPermissionStateThe permission state for accessing motion data on the current platform.1.0.0

PluginListenerHandle

PropType
remove() => Promise<void>

Type Aliases

GetMeasurementResult

Alias for the most recent measurement.

Measurement

AccelerometerPermissionState

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

PermissionState | 'limited'

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

MeasurementEvent

Event payload emitted when {@link CapacitorAccelerometerPlugin.startMeasurementUpdates} is active.

Measurement

Credit

This plugin was inspired from: https://github.com/kesha-antonov/react-native-background-downloader

版本与发布记录

@capgo/capacitor-accelerometer 共发布 64 个版本,首次发布于 2025/10/27;过去 12 个月发布了 57 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.55latest2026/11/09今天
8.0.542026/11/026 天前
8.0.532026/10/2613 天前
8.0.522026/10/1920 天前
8.0.512026/10/1525 天前
8.0.502026/10/1327 天前

关于 @capgo/capacitor-accelerometer 的常见问题

@capgo/capacitor-accelerometer 是什么?

Read device accelerometer measurements with Capacitor

如何安装 @capgo/capacitor-accelerometer?

在项目目录运行 npm install @capgo/capacitor-accelerometer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-accelerometer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-accelerometer 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-accelerometer 可以商用吗?

@capgo/capacitor-accelerometer 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-accelerometer 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-accelerometer 在 2026/10/09 – 2026/11/07 这 30 天内被下载 42,227 次,日均约 1,408 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-accelerometer 还在维护吗?

最新版本 8.0.55 发布于 2026/11/09(今天);至今共发布 64 个版本,其中过去 12 个月发布了 57 个;首次发布于 2025/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。