首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

代码开展监听注册电量变化

2012-09-22 
代码进行监听注册电量变化public class Main extends Activity {? private TextView contentTxt? private

代码进行监听注册电量变化

public class Main extends Activity {
? private TextView contentTxt;
? private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
? ? @Override
? ? public void onReceive(Context arg0, Intent intent) {
? ? ? // TODO Auto-generated method stub
? ? ? int level = intent.getIntExtra("level", 0);
? ? ? contentTxt.setText(String.valueOf(level) + "%");
? ? }
? };

? @Override
? public void onCreate(Bundle icicle) {
? ? super.onCreate(icicle);
? ? setContentView(R.layout.main);
? ? contentTxt = (TextView) this.findViewById(R.id.monospaceTxt);
? ? this.registerReceiver(this.mBatInfoReceiver,
? ? new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
? }
}

1 楼 max8888888 2011-03-25   虽然对,但是只是显示一次吧?

热点排行