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

Turbo3

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

Erel

Administrator
Staff member
Licensed 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
 
Top