开发者

how to get battery temperature in android [duplicate]

开发者 https://www.devze.com 2023-03-05 02:33 出处:网络
This question already has answers here: 开发者_开发百科 Closed 11 years ago. Possible Duplicate: Get temperature of battery on android
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

精彩评论

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