<!--
source: https://blueos.niceshare.site/api/system/battery/
site: 蓝河文档馆
summary: 电量信息 — 蓝河文档馆 BlueOS 开发文档
-->
---
title: '电量信息'
description: '```json'
lastUpdated: 2024-08-13T07:19:43.000Z
---

## 接口声明

```json
{ "name": "blueos.hardware.battery" }
```

## 导入模块

```ts
import battery from '@blueos.hardware.battery' 或 const battery = require('@blueos.hardware.battery')
```

## 接口定义

### battery.getStatus(OBJECT)

获取当前设备的电量信息。

#### 参数：

| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| success | Function | 否 | 成功回调 |
| fail | Function | 否 | 失败回调 |
| complete | Function | 否 | 执行结束后的回调 |

##### success 返回值：

| 参数值 | 类型 | 说明 |
| --- | --- | --- |
| charging | Boolean | 是否正在充电 |
| level | Number | 当前电量，0.0 - 1.0 之间 |

#### 示例：

```ts
battery.getStatus({
  success: function (data) {
    console.log(`handling success: ${data.level}`)
  },
  fail: function (data, code) {
    console.log(`handling fail, code = ${code}`)
  },
})
```

### battery.getStatusSync()

同步获取当前设备的电量信息。

#### 参数

无

#### 返回值

| 参数值 | 类型 | 说明 |
| :-- | :-- | :-- |
| batteryStatus | Object | 当前电量信息 |

#### batteryStatus 参数描述

| 参数值 | 类型 | 说明 |
| :-- | :-- | :-- |
| charging | Boolean | 是否正在充电 |
| level | Number | 当前电量，0.0 - 1.0 之间 |

#### 示例

```ts
const batteryStatus = battery.getStatusSync()
```
