你的位置:首页 > 操作系统

[操作系统]手机影音5


1.设置电池状态

1_监听电量变化广播

private void initData() {	utils = new Utils();	//注册监听电量变化广播	IntentFilter filter = new IntentFilter();	filter.addAction(Intent.ACTION_BATTERY_CHANGED);//监听电量变化	receiver = new MyBatterReceiver();	registerReceiver(receiver, filter);}private class MyBatterReceiver extends BroadcastReceiver{	@Override	public void onReceive(Context context, Intent intent) {	  //电量值,设置默认为0	  level = intent.getIntExtra("level", 0);
     }}

2_电量刷新方法

/** * 设置电量的状态*/protected void setBatterStatus() {	if(level <=0){		iv_battery_status.setImageResource(R.drawable.ic_battery_0);	}else if(level >0&& level <=10){		iv_battery_status.setImageResource(R.drawable.ic_battery_10);	}else if(level >10&&level <=20){		iv_battery_status.setImageResource(R.drawable.ic_battery_20);	}else if(level >20&&level <=40){		iv_battery_status.setImageResource(R.drawable.ic_battery_40);	}else if(level >40&&level <=60){		iv_battery_status.setImageResource(R.drawable.ic_battery_60);	}else if(level >60&&level <=80){		iv_battery_status.setImageResource(R.drawable.ic_battery_80);	}else if(level >80&&level <=100){		iv_battery_status.setImageResource(R.drawable.ic_battery_100);	}else{		iv_battery_status.setImageResource(R.drawable.ic_battery_100);	}}

2.得到系统时间并且更新显示