最近碰到一个需要重启Android系统的需求,经过网络查询,使用如下代码进行系统级别的重启工作:
private void rebootSystem(){
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
pm.reboot(null);
}
但运行了之后,抛出如下错误:
ava.lang.SecurityException: Neither user 10141 nor current process has android.permission.REBOOT.
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.os.IPowerManager$Stub$Proxy.reboot(IPowerManager.java:698)
at android.os.PowerManager.reboot(PowerManager.java:889)
at cn.xxx.xxx.ui.MainNewActivity.rebootSystem(MainNewActivity.java:389)
at cn.xxx.xxx.ui.MainNewActivity.clickItemSetting(MainNewActivity.java:141)
at cn.xxx.xxx.ui.MainNewActivity_ViewBinding$1.doClick(MainNewActivity_ViewBinding.java:48)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:26)
at android.view.View.performClick(View.java:4807)
at android.view.View$PerformClick.run(View.java:20106)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5568)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
出现原因:经过众多网友提供的经验,想要在app里面重启Android系统,必须拥有系统权限。
解决办法:apk的签名使用系统签名,即可完成系统重启。
评论已关闭