Android实现侦听电池状态显示、电量及充电动态显示的方法(2)
这里真正 处理图片变换 的是以下几句话: switch (status) { case BatteryManager.BATTERY_STATUS_UNKNOWN: statusString = "unknown"; break; case BatteryManager.BATTERY_STATUS_CHARGING: sta
这里真正处理图片变换的是以下几句话:
switch (status) { case BatteryManager.BATTERY_STATUS_UNKNOWN: statusString = "unknown"; break; case BatteryManager.BATTERY_STATUS_CHARGING: statusString = "charging"; battery_image.setImageResource(R.drawable.stat_sys_battery_charge); battery_image.getDrawable().setLevel(level); break; case BatteryManager.BATTERY_STATUS_DISCHARGING: statusString = "discharging"; battery_image.setImageResource(R.drawable.stat_sys_battery); battery_image.getDrawable().setLevel(level); break; case BatteryManager.BATTERY_STATUS_NOT_CHARGING: statusString = "not charging"; break; case BatteryManager.BATTERY_STATUS_FULL: statusString = "full"; break; }
4.在onResume方法中注册消息处理器
registerReceiver(mIntentReceiver, mIntentFilter);
5.在onPause方法中注销
unregisterReceiver(mIntentReceiver);
希望本文所述对大家的Android程序设计有所帮助。
精彩图集
精彩文章