This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 传感器
一个提供访问设备加速度计、气压计、运动传感器、陀螺仪、光线传感器、磁力计和计步器的库
expo-sensors 提供多种 API,用于访问设备传感器,以测量运动、方向、压力、磁场、环境光和步数。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
在应用配置中进行配置
如果项目使用配置插件(持续原生生成(CNG)),可以使用内置的配置插件配置 expo-sensors。此插件允许你配置各种无法在运行时设置、且需要构建新的应用二进制文件才能生效的属性。如果应用不使用 CNG,则需要手动配置此库。
Example app.json with config plugin
Configurable properties
API
import * as Sensors from 'expo-sensors'; // OR import { Accelerometer, Barometer, DeviceMotion, Gyroscope, LightSensor, Magnetometer, MagnetometerUncalibrated, Pedometer, } from 'expo-sensors';
权限
Android
从 Android 12(API 级别 31)开始,系统对每个传感器的更新频率限制为 200Hz。
如果需要的更新频率高于 200Hz,必须将以下权限添加到 app.json 中的 expo.android.permissions 数组。
Are you using this library in an existing React Native app?
如果你没有使用持续原生生成(CNG),或者正在手动使用原生 android 项目,请将 HIGH_SAMPLING_RATE_SENSORS 权限添加到项目的 android/app/src/main/AndroidManifest.xml 中:
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
iOS
此库使用以下使用说明键:
可用的传感器
有关详细信息,请参阅所需传感器的文档:
在所有平台上测量设备加速度。
在 Android 和 iOS 平台上测量压力。
在所有平台上测量设备运动。
在所有平台上测量设备旋转。
在 Android 和 iOS 平台上测量磁场。
在 Android 平台上测量环境光。
在 Android 和 iOS 平台上测量步数。