PowerManage.reboot(""); 为啥不行···

OnKeyDown灬Sona 2016-07-30 05:38:04
PowerManager pManager=(PowerManager) getSystemService(Context.POWER_SERVICE); //重启​
pManager.reboot("");


为啥提示我 要创建 getSystemService 方法?
...全文
576 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
OnKeyDown灬Sona 2016-07-30
  • 打赏
  • 举报
回复
试了网上的 关机 try { //获得ServiceManager类 Class ServiceManager = Class .forName("android.os.ServiceManager"); //获得ServiceManager的getService方法 Method getService = ServiceManager.getMethod("getService", java.lang.String.class); //调用getService获取RemoteService Object oRemoteService = getService.invoke(null,Context.POWER_SERVICE); //获得IPowerManager.Stub类 Class cStub = Class .forName("android.os.IPowerManager$Stub"); //获得asInterface方法 Method asInterface = cStub.getMethod("asInterface", android.os.IBinder.class); //调用asInterface方法获取IPowerManager对象 Object oIPowerManager = asInterface.invoke(null, oRemoteService); //获得shutdown()方法 Method shutdown = oIPowerManager.getClass().getMethod("shutdown",boolean.class,boolean.class); //调用shutdown()方法 shutdown.invoke(oIPowerManager,false,true); } catch (Exception e) { UiUtils.logd(CASE_ID, "==============yao si le ================"); } 都可以,为啥自带的重启不可以

58,441

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧