android service 中弹提示框

本文介绍了一个使用Android系统对话框提醒用户重启设备并执行root权限下特定命令的示例。通过创建一个AlertDialog,设置标题和按钮,实现延迟显示对话框的功能,并在点击按钮后执行重启到恢复模式并加载更新包的命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                builder = new AlertDialog.Builder(getApplicationContext());
			builder.setTitle("请拔掉U盘,点击重启!");
			builder.setPositiveButton("重启", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					ArrayList<String>  commandList = new ArrayList<>();
					commandList.add("echo --update_package=/cache/recovery/update.zip >                                 
                       /cache/recovery/command");
					commandList.add("reboot recovery");
					ExecuteAsRoot executeAsRoot = new ExecuteAsRoot(commandList);
					executeAsRoot.execute();
				}
			});	
			final AlertDialog dialog = builder.create();
			//在dialog  show方法之前添加如下代码,表示该dialog是一个系统的dialog
			//dialog.getWindow().setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
if (Build.VERSION.SDK_INT>=26) {//8.0新特性
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
}else{
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
}
			new Thread(){
				public void run() {
					SystemClock.sleep(4000);
					hanlder.post(new Runnable() {
					@Override
					public void run() {
						dialog.show();
						}
					});
				};
			}.start();

参考:

https://blog.youkuaiyun.com/djun100/article/details/23756681

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值