Italian Help BatteryLevel

Piappo

Member
Licensed User
Longtime User
Salve a tutti, premetto che sto cominciando adesso con b4a.Vorrei visualizzare il livello batteria su una edittext con la libreria OSllbrary ma mi da errore (null pointer exeption)non in compilazione ma sul device.

ecco il codice:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

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 batteria As OperatingSystem
batteria.Initialize("batteria")

Dim EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("prova")



EditText1.Text = batteria.BatteryLevel
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Avete qualche idea?

Vi ringrazio anticipatamente
 

Piappo

Member
Licensed User
Longtime User
Grazie per la risposta timo funziona perfettamente con la libreria phone.
Avevo optato per la oslibrary perchè sembrava piu veloce..

Grazie di nuovo
 

fifiddu70

Well-Known Member
Licensed User
Longtime User
sono arrivato in ritardo :)
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
   
   Dim PE As PhoneEvents
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 EditText1 As EditText
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("OS")
       PE.Initialize("PE")
   


End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub 
Sub PE_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
    Log("BatteryChanged: Level = " & Level )
   EditText1.Text=Level
End Sub
lo metto lo stesso
 
Top