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
2010-10-22 13:40:55
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
2010-10-22 13:59:19
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
2010-10-22 14:26:10
@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
2010-10-22 14:38:31
According to the documentation EXTRA_TEMPERATURE happens to be a String. It's also static and therefore will always be "temperature".
Christian
2010-10-22 14:11:45
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
2010-10-22 14:28:36