Possible Duplicate:
Get temperature of battery on android
Hi
I want to get battery temperature in android. How can i achieve the same? Is there any api available? Please help.
You can find here how to register to battery changes. Using the extra value (EXTRA_TEMPERATURE
) you can get the temperature.
In short (taken from the link above and modified a bit):
Declare broadcast receiver:
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
....
}
};
and in onCreate
, add:
this.registerReceiver(this.mBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
精彩评论