需求:电池电量低于17%要弹出弹窗,不会自动消失,可以被用户手动点击关闭。电池电量低于16%也要弹出弹窗,此时将锁定界面,无法关闭,直到更换电池。
导包
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.BatteryManager;
import android.widget.Toast;
代码
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
public class PhoneWindowManager implements WindowManagerPolicy {
//状态变量,防止重复执行
private boolean mLowPowerWarnHaveRunned = false;
private boolean mLowPowerWarnIsRunning = false;
private boolean mShutdownIsRunning = false;
//Handler、AlertDialog变量
private Handler mLowPowerWarnHandler;
private Handler mShutdo