javanew(intentFilter,"android.content.IntentFilter","String","android.intent.action.BATTERY_CHANGED")
java(batteryStatus,activity,"android.content.Context.registerReceiver","android.content.BroadcastReceiver",null,"android.content.IntentFilter",intentFilter)
//BATTERY_CHANGED是一个粘性广播,所以传null值就能拿到当前状态
java(status,batteryStatus,"android.content.Intent.getIntExtra","String","status","int",-1)
f(status == 2) {
tw("充电中")
} else f(status == 3 || status == 4) {
tw("放电中")
} else f(status == 5) {
tw("已充满")
}
java(plug,batteryStatus,"android.content.Intent.getIntExtra","String","plugged","int",-1)
f(plug == 1) {
tw("AC充电中")
} else f(plug == 2) {
tw("USB充电中")
} else f(plug == 4) {
tw("无线充电中")
}
java(level,batteryStatus,"android.content.Intent.getIntExtra","String","level","int",-1)
//当前电池电量
java(scale,batteryStatus,"android.content.Intent.getIntExtra","String","scale","int",-1)
//最大电池电量
ss("当前电池电量:" + level + "
最大电池电量:" + scale,msg)
tw(msg)