iOS Question How to read device battery level?

Turbo3

Active Member
Licensed User
Longtime User
Looks like granularity is in 10% units ( returns 0.1, 0.2, 0.3 ...). I was hoping for 1% granularity like we get on Android devices with B4A.
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
I just did some testing and found that different iOS devices have different levels of granularity. The iPhone 4 I was testing has 5% not the original 10% I listed above.

iPhone 4 (MD146LL/A) has 5% steps (1.0 -> 0.95 ->0.90) Even though the battery gauge on notification line steps in 1% units

iPad (Model MC981LL/A) has 1% steps (1.0 ->0.99 -> 0.98)

The device Erel was using also has the 1% steps.
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
B4X:
'0 = Unknown
'1 = Unplugged
'2 = Charging
'3 = Full
Sub GetBatteryState 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