这是我的 BattreyInfo.java 文件。我正在尝试提取电池温度并将其显示在我的屏幕上。Eclipse 说BroadcastReciever
无法解析为类型。我不明白。我已经正确导入了包。它也无法识别该onRecieve
功能。我必须为其他课程或其他东西BroadcastReciever
吗?
package com.example.batterywidget;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.BatteryManager;
import android.widget.TextView;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.graphics.Color;
import android.view.View;
public class BatteryInfo extends Activity {
private TextView BatTemp;
BroadcastReceiver mBatInfoReciever = new BroadcastReceiver(){
@Override
public void onRecieve(Context arg0, Intent intent){
int temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
BatTemp.setText(String.valueOf(temp) + "%");
}
};
//called when the activity is first created
@Override
public void onCreate(Bundle binfo){
super.onCreate(binfo);
setContentView(R.layout.batteryinfo);
BatTemp = (TextView) this.findViewById(R.id.battery_temp);
}
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(mBatInfoReceiver, filter);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mBatInfoReceiver);
}
}