开发者

how to get battery temperature in android [duplicate]

This question already has answers here: 开发者_开发百科 Closed 11 years ago.

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜