Android12源码 重启按钮确认重启弹窗

private static AlertDialog.Builder builder;
private static AlertDialog alert;


Intent rebootIntent = new Intent("android.intent.action.ACTION_REBOOT");
if(alert != null){
   alert.dismiss();
}
// 创建弹窗
builder = new AlertDialog.Builder(mContext);
builder.setMessage("设备即将重启,确定继续吗?")
       .setTitle("重启")
       //设置点击外部是否关闭弹窗
       .setCancelable(true)
       .setPositiveButton("重启", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
              // 用户选择重启,发送广播
              mContext.sendBroadcast(rebootIntent);
            }
        })
        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
              // 取消关闭,需要通过反射机制取消关闭
                  try {
                       // 反射方法参数为空,无返回值
                       // Method cancelMethod = intent.getClass().getDeclaredMethod("cancel");
                       // cancelMethod.setAccessible(true);
                       // cancelMethod.invoke(intent);
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                   }  
               });
alert = builder.create();
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alert.show();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值