iOS Question Is there a way to tell if device on external power?

Turbo3

Active Member
Licensed User
Longtime User
Is there a way to tell if the iOS device is running on external power instead of off internal battery power?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes.
B4X:
'0 = Unknown, 1 = Unplugged, 2 = Charging, 3 = Full
Sub BatteryState As Int
   Dim no As NativeObject
   no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
   If no.GetField("batteryMonitoringEnabled").AsBoolean = False Then
     no.SetField("batteryMonitoringEnabled", True)
   End If
   Return no.GetField("batteryState").AsNumber
End Sub
 
Upvote 0
Top