Android Question how to know pluged charger ?

khosrwb

Active Member
Licensed User
Longtime User
hi Erel
how can I know charger ( or other devices ) is pluged ?
I want when attached charger to my phone , run my app
 
Last edited:

socialnetis

Active Member
Licensed User
Longtime User
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
 
Upvote 0
Top