tags:

views:

100

answers:

2

How do I get the temperature of the battery in android?

+3  A: 

http://developer.android.com/reference/android/os/BatteryManager.html

public static final String EXTRA_TEMPERATURE
Extra for ACTION_BATTERY_CHANGED: integer containing the current battery temperature.

Select0r
What is ACTION_BATTERY_CHANGED about? Do I have to lunch an intent to get the temperature? Do I have to listen to some system wide intent?
Christian
Google is your friend: http://www.tutorialforandroid.com/2009/01/getting-battery-information-on-android.html That tutorial is about how to get the battery level but together with the docs-link I posted, I'm sure you can figure out how to get the battery-temperature, just use "temperature" instead of "level" ...
Select0r
@Christian: You do not need to register an actual `BroadcastReceiver` if you do not want to. Call `registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED))`, and it will return the last Intent that was broadcast for this action. Use the `EXTRA_TEMPERATURE` extra to get the value you seek.
CommonsWare
+1  A: 

Try reading the static int BatteryManager.EXTRA_TEMPERATURE

GôTô
According to the documentation EXTRA_TEMPERATURE happens to be a String. It's also static and therefore will always be "temperature".
Christian
True, but the doc also says: "Extra for ACTION_BATTERY_CHANGED" - so your static String is just the key to get the temperature from ACTION_BATTERY_CHANGED.
Select0r