# Battery プラグイン

このプラグインの詳細は、[こちらの原文 ( GitHub )](https://github.com/apache/cordova-plugin-battery-status) をご確認ください。

## プラグイン ID

```
cordova-plugin-battery-status
```

## プラグインの追加方法&#x20;

このプラグインを使用する場合は、Monaca クラウド IDE の \[ Cordova プラグインの管理 ] 上で、\
`Battery` プラグインを[有効](/products_guide/monaca_ide/dependencies/cordova_plugin.md#cordova-puraguin-noinpto)にします。

## API の解説

### ステータス オブジェクト

このプラグインのすべてのイベントは、次のプロパティを持つオブジェクトを返します。

| プロパティ       | 型   | 解説                 |
| ----------- | --- | ------------------ |
| `level`     | 数値  | バッテリー充電率 (`0-100`) |
| `isPlugged` | 真偽値 | 端末が充電中かを示す真偽値      |

### batterystatus イベント

バッテリの充電率が少なくとも1パーセント変化したとき、または端末の充電を開始、または停止されたときに発火します。\
バッテリーの状態を含む [object](#suttasu-obujekuto) を返します。

#### 例

```javascript
window.addEventListener("batterystatus", onBatteryStatus, false);

function onBatteryStatus(status) {
    console.log("Level: " + status.level + " isPlugged: " + status.isPlugged);
}
```

### batterylow イベント

バッテリー残量が非常に少なくなった場合に、このイベントが発火します。

しきい値は、端末によって異なります。

バッテリーの状態を示すプロパティが格納された [object](#suttasu-obujekuto) を返します。

#### 例

```javascript
window.addEventListener("batterylow", onBatteryLow, false);

function onBatteryLow(status) {
    alert("Battery Level Low " + status.level + "%");
}
```

### batterycritical イベント

バッテリー充電率が臨界充電しきい値に達した場合に、このイベントが発火します。しきい値は、端末によって異なります。\
バッテリーの状態を示すプロパティが格納された [object](/reference/core-cordova-plugins/cordova_9.0/battery-status.md#suttasu-obujekuto) を返します。

#### 例

```javascript
window.addEventListener("batterycritical", onBatteryCritical, false);

function onBatteryCritical(status) {
    alert("Battery Level Critical " + status.level + "%\nRecharge Soon!");
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ja.docs.monaca.io/reference/core-cordova-plugins/cordova-12.0/battery-puraguin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
