在做一些系统应用中,需要添加重启功能,查询一些资料,最后还是通过反射解决这个问题,代码如下:

Class<?> serviceManager = Class.forName("android.os.ServiceManager");                Method getService = serviceManager.getMethod("getService", String.class);                Object remoteService = getService.invoke(null, Context.POWER_SERVICE);                Class<?> stub = Class.forName("android.os.IPowerManager$Stub");                Method asInterface = stub.getMethod("asInterface", IBinder.class);                Object powerManager = asInterface.invoke(null, remoteService);                Method shutdown = powerManager.getClass().getDeclaredMethod("reboot",                        boolean.class, String.class, boolean.class);                shutdown.invoke(powerManager, false, "", true);

更多相关文章

  1. Android(安卓)使用RecycleView制作头像堆叠效果
  2. flutter集成推送功能-小米推送集成
  3. 自己写的一个android小应用 手电筒
  4. [Android]如何获得heap的大小
  5. Android(安卓)Build System ---- how to add your product and b
  6. Android(安卓)强制下线功能 第一行代码
  7. android代码库之执行Shell命令或者脚本
  8. 在android中如何在代码中设置textview的属性和效果
  9. Androd学习笔记——Android(安卓)Camera Parameters分析

随机推荐

  1. Android(安卓)4.4 Fence在SurfaceFlinger
  2. Android(安卓)实现item可左右滑动移除的G
  3. Android(安卓)高仿微信发朋友圈浏览图片
  4. Android(安卓)属性动画代码分析(基于Obje
  5. android webview内嵌网页js解析json 并根
  6. Android无缝切换主题,动态换肤
  7. 如何取得Android(安卓)系统的源代码--全
  8. 挑战独立开发项目能力--IT蓝豹
  9. Android(安卓)Studio如何import module(针
  10. Android项目实践系列(二) - 深度定制Logge