如果你有开发机,那么可以应用下面的例子来查看当前系统中电池能量信息
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)); } }
简短说明(Quick explanation):
通过创建BroadcastReceiver来侦测系统中有关电池Intent(ACTION_BATTERY_CHANGED)的变化,一旦有接收到相关事件,将会读取当前电量情况,并通过TextViews显示在当前屏幕。
Layout 源码:




