Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim J As JavaObject
Dim Timer1 As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lb1 As Label
Dim lb2 As Label
Dim lb3 As Label
Dim lb4 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
J.InitializeContext
J=J.InitializeNewInstance("android.os.BatteryManager",Null)
lb1.Initialize("")
Activity.AddView(lb1,20dip, 40dip,100%X-20dip,40dip)
lb2.Initialize("")
Activity.AddView(lb2,20dip, 80dip,100%X-20dip,40dip)
lb3.Initialize("")
Activity.AddView(lb3,20dip, 120dip,100%X-20dip,40dip)
lb4.Initialize("")
Activity.AddView(lb4,20dip, 160dip,100%X-20dip,40dip)
Timer1.Initialize("Timer1",1000)
End Sub
Sub Activity_Resume
Timer1.Enabled=True
End Sub
Sub Timer1_Tick
Dim property As Int
'2: INSTANT
property=2
Dim instantCurrentConsumptionuA As Int=J.RunMethod("getIntProperty",Array(property)) ' 2=BATTERY_PROPERTY_CURRENT_NOW in microAmperes
Log("Consumption is: "&instantCurrentConsumptionuA)
'3: AVERAGE
property=3
Dim averageCurrentConsumptionuA As Int =J.RunMethod("getIntProperty",Array(property))
Log("Average Consumption is: "&averageCurrentConsumptionuA)
'4: CAPACITY
property=4
Dim batteryCapacity As Int =J.RunMethod("getIntProperty",Array(property))
Log("Capacity: "&batteryCapacity)
'5: COUNTER (long)
property=5
Dim batteryEnergyCounternWh As Long =J.RunMethod("getLongProperty",Array(property))
Log("Energy counter: "&batteryEnergyCounternWh)
lb1.text = "Instant: "&instantCurrentConsumptionuA
lb2.text = "Average: "&averageCurrentConsumptionuA
lb3.text = "Capacity: "&batteryCapacity
lb4.text = "Energy Counter: "&batteryEnergyCounternWh
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Timer1.Enabled=False
End Sub