This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 电池 iconExpo 电池

提供物理设备电池信息以及相应事件监听器的库。

Android
iOS (device only)
Web
Included in Expo Go
Recommended version:
~58.0.3

expo-battery 提供物理设备的电池信息(如电池电量、设备是否正在充电等)以及相应的事件监听器。

安装

🌐 Installation

Terminal
- npx expo install expo-battery
- yarn expo install expo-battery
- pnpm expo install expo-battery
- bun expo install expo-battery

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

🌐 Usage

Basic Battery usage
import { useBatteryLevel } from 'expo-battery'; import { StyleSheet, Text, View } from 'react-native'; export default function App() { const batteryLevel = useBatteryLevel(); return ( <View style={styles.container}> <Text>Current Battery Level: {batteryLevel}</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, marginTop: 15, alignItems: 'center', justifyContent: 'center', }, });

应用接口

🌐 API

import * as Battery from 'expo-battery';

No API data file found, sorry!