应客户需求,在电量为10,7,5,2的时候,弹出低电量警告框,并且每次弹框,点一下确定就不再弹了。
/frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerUI.java里有个监听电池状态的广播,打log发现,每隔10秒,电池状态会报一次,具体修改如下
AlertDialog mBadWaringDialog = null;
//低电量警告框
private void showWarningLowBatteryAlert(int battery) {
dismissWarningLowBatteryDialog();
AlertDialog.Builder b = new AlertDialog.Builder(mContext);
b.setCancelable(true);
b.setMessage( mContext.getResources().getString(R.string.hct_battery_level) +
battery + mContext.getResources().getString(R.string.hct_charging_tip));
b.setIconAttribute(android.R.attr.alertDialogIcon);
b.setPositiveButton(android.R.string.ok, null);