方法一:adb shell dumpsys battery
在Terminal 里输入命令行 adb shell dumpsys battery
我实测时会有两个level,status,present 目前还不清楚是怎么回事
方法二:读取电池信息相关文件
可做定时器,每隔30秒读取一次获得实时电量,视具体需求。
package com .xxx
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Created by dell on 2020/6/17.
*/
public class BatteryUtil {
private String AC_ONLINE_PATH = "/sys/class/power_supply/ac/online"; //AC电源连接状态
private String USB_ONLINE_PATH ="/sys/class/power_supply/usb/online"; //USB电源连接状
private String BATTERY_STATUS_PATH= "/sys/class/power_supply/battery/status"; //充电状
private String BATTERY_HEALTH_PATH="/s