Попробуйте:
private class mBatInfoReceiver extends BroadcastReceiver{
int temp = 0;
float get_temp(){
return (float)(temp / 10);
}
@Override
public void onReceive(Context arg0, Intent intent) {
temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0);
}
};
, затем определите в объявлениях переменных:
private mBatInfoReceiver myBatInfoReceiver;
и в onCreate:
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
// ...
// Add this
myBatInfoReceiver = new mBatInfoReceiver();
this.registerReceiver(this.myBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
позже вызовите, например, в OnClickListener()
float temp = myBatInfoReceiver.get_temp();
String message = "Current " + BatteryManager.EXTRA_TEMPERATURE + " = " +
temp + Character.toString ((char) 176) + " C";