Android Question Device temperature monitoring

Lakhtin_V

Active Member
Licensed User
Longtime User
For my project, it is important to monitor the device overheating. How can I do control the temperature of the device? The my code I try does not work

B4X:
Sub Process_Globals
    Dim phone As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    If phone.SdkVersion >= 21 Then ' Check, ver Android if is 5.0 (Lollipop) and more
        Dim temperature As Float
        temperature = phone.GetTemperature
        Log("Temperature device: " & temperature & " °C")
        ToastMessageShow("Temperature device: " & temperature & " °C", True)
    Else
        ToastMessageShow("You version Android .", True)
    End If
End Sub
 

peacemaker

Expert
Licensed User
Longtime User
Temperature of the built-in battery sensor can be got by the PhoneEvents of Phone lib.

B4X:
Dim Pe As PhoneEvents
....
Sub pe_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)

CurT = Intent.GetExtra("temperature")
CurT = CurT/10    'temperature of the first main device battery (there are Android devices with 2 batteries, and there more complex battery info intent)
Pe.StopListening
End Sub

'timer
Sub tim_Tick
Pe.Initialize("pe")
End sub

Note that the temperature is going higher at higher device work load, or during battery charging (while it's < 100%).
 
Last edited:
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Thank you so much, the wonderful advice works everything. I hope maybe you know how to read the parameter that describes the load on the processor. You need some kind of general integral parameter
 
Upvote 0
Top