答案 0 :(得分:7)
您可以找到here如何注册电池更改。使用额外值(EXTRA_TEMPERATURE
)可以获得温度。
简而言之(取自上面的链接并稍加修改):
声明广播接收器:
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
....
}
};
并在onCreate
中添加:
this.registerReceiver(this.mBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));