当前位置:首页 » 安卓系统 » android关机实现

android关机实现

发布时间: 2024-11-15 20:26:42

A. android 中如何实现关机、重启

主要思路:1、需要源码才能编译
2、修改项目的Android.mk文件,添加
LOCAL_CERTIFICATE := platform
3、AndroidManifest.xml中添加权限
3.1 manifest标签中添加
android:sharedUserId="android.uid.system"
3.2 使用权限
<uses-permission android:name="android.permission.SHUTDOWN"/
4、java代码
// 创建Intent
// 如果是要重启,则使用Intent.ACTION_REBOOT
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
// 设置是否需要用户确认,若不需要,可以不设置或设置为false
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, true);
// 当作新任务执行
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// 启动startActivity(intent);
据说还可以使用Broadcast的方式调用,不过我试了一下,窗口是出来了,但一直停在关机的进度条那。不知道是不是机子的问题。代码如下:Intent i = new Intent(Intent.ACTION_REBOOT);
i.putExtra("nowait", 1);
i.putExtra("interval", 1);
i.putExtra("window", 0);
sendBroadcast(i);
10-22 10:02 回答curie_871073

B. android完整的java关机代码

必须有root权限的才可以,有的话执行命令行就可以了 RuntimegetRuntime()exec(new String[]{ "su", "-c", "poweroff -f" }); RuntimegetRuntime()exec(new String[]{ "su", "-c", "reboot" });android完整的java关机代码?

C. android 中如何实现关机、重启求解,谢谢

如果已经root权限,那么可以实验一下下面的代码:
try{
Process proc =Runtime.getRuntime().exec(newString[]{"su","-c","reboot -p"});
proc.waitFor();
}catch(Exception ex){
ex.printStackTrace();
}

D. android 中如何实现关机,重启

关机命令

Runtime.getRuntime().exec("su -c \"/system/bin/shutdown\"");

重启命令

Runtime.getRuntime().exec("su -c \"/system/bin/reboot\"");

注意:手机必须root,否则这两个命令无法执行。

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:593
制作脚本网站 发布:2025-10-20 08:17:34 浏览:888
python中的init方法 发布:2025-10-20 08:17:33 浏览:581
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:765
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:684
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1013
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:255
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:114
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:806
python股票数据获取 发布:2025-10-20 07:39:44 浏览:712