Hi, there is a Phone library, which has a "batteryChanged" event, that let you know if the phone is plugged, unplugged, and how is the percentage of the battery.
Ussage:
B4X:
Sub Globals
Dim P as Phone
End Sub
Sub Activity_Create(FirstTime As Boolean)
P.Initialize("P")
End Sub
Sub P_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
Log("BatteryChanged: Level = " & level & ", Scale = " & scale & ", Plugged = " & Plugged)
End Sub
If you want to detect when your app is not running, then you should use it in a Service