Android 2.2:以编程方式重新启动设备
我想知道是否有办法通过代码重新启动设备。我尝试过:
Intent i = new Intent(Intent.ACTION_REBOOT);
i.putExtra("nowait", 1);
i.putExtra("interval", 1);
i.putExtra("window", 0);
sendBroadcast(i);
并添加了 REBOOT
权限,但仍然不起作用。
谢谢
I would like to know if there is a way to reboot the device through code. Ive tried:
Intent i = new Intent(Intent.ACTION_REBOOT);
i.putExtra("nowait", 1);
i.putExtra("interval", 1);
i.putExtra("window", 0);
sendBroadcast(i);
And added permissions for REBOOT
but it still doesnt work.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这似乎对我有用:
This seemed to work for me:
仍然适用于 root 设备,但如果您想要更安全(process.waitFor() 是有条件的,在单独的 try-catch 中,我们有适当的异常处理,重新启动后在命令中添加“now”,这对于某些设备等是必需的。 )也许还有更干净的代码,看看这个:
Still for rooted devices, but in case you want safer (process.waitFor() is conditioned, in separate try-catch, we have proper exception handling, "now" added in command after reboot, which is necessary for some devices, etc.) and maybe cleaner code, take a look at this:
您可以使用 PowerManager 使其重新启动(这并不能保证它会重新启动 - 操作系统可能会取消它):
链接
链接#2
You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it):
links
link #2
我正在使用 Xamarin。对我来说,解决方案是:
I am using Xamarin. For me the solution is:
这是一个解决方案。请记住,设备必须已root。
Here is a solution. Remember, the device must be rooted.
如果手机已root,实际上非常简单:
第一个命令将请求超级用户权限。第二,将重新启动手机。
清单文件中不需要额外的权限,因为实际的重新启动是由执行的命令处理的,而不是应用程序。
If the phone is rooted, it's actually very simple:
The first command will ask for superuser permission. The second, will reboot the phone.
There is no need for extra permissions in the manifest file since the actual rebooting is handled by the executed comamand, not the app.