首页 > 系统 > Android > 正文

Android实现关机重启的方法分享

2019-10-24 20:38:23
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Android实现关机重启的方法,需要的朋友可以参考下
 

实现系统重启的APK需要system的权限,在AndroidManifest.xml中增加android:sharedUserId="android.uid.system",再修改签名即可;

具体方法参考:

点击打开链接

1、使用PowerManager来实现:
代码:

复制代码代码如下:

private void rebootSystem(){  
    PowerManager pManager=(PowerManager) getSystemService(Context.POWER_SERVICE);  
    pManager.reboot("");  
}  

 

2、发送REBOOT广播:
代码:

复制代码代码如下:

private void rebootSystem(){
 Intent reboot = new Intent(Intent.ACTION_REBOOT);
 reboot.putExtra("nowait", 1);
 reboot.putExtra("interval", 1);
 reboot.putExtra("window", 0);
 sendBroadcast(reboot);
}
 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表