Android Question How to detect power outage?


Licensed User
Longtime User
Hi everyone!
I need to build an app that sends an SMS message when the phone looses power connection.
Is there a library that helps detect when the phone is unplugged, and triggers an event?
Thank you!


Well-Known Member
Licensed User
Longtime User
I use this:

Sub PhoneEvent_BatteryChanged( Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent )
    PluggedStatus = Plugged   
    ChargeLevel = Level
    If PluggedStatus = False And ChargeLevel < 50 Then
        pws.KeepAlive( False )
        pws.KeepAlive( True )
    End If
End Sub ' PhoneEvent_BatteryChanged()

Plugged tells you if the phone is charging.
In this example, I run the pws.KeepAlive() function depending on the charge level.
The event gets called when the charging status or charge level changes.
Upvote 0