android 9.0系统重启的代码详解
16lz
2021-01-24
在做一些系统应用中,需要添加重启功能,查询一些资料,最后还是通过反射解决这个问题,代码如下:
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);
更多相关文章
- Android(安卓)使用RecycleView制作头像堆叠效果
- flutter集成推送功能-小米推送集成
- 自己写的一个android小应用 手电筒
- [Android]如何获得heap的大小
- Android(安卓)Build System ---- how to add your product and b
- Android(安卓)强制下线功能 第一行代码
- android代码库之执行Shell命令或者脚本
- 在android中如何在代码中设置textview的属性和效果
- Androd学习笔记——Android(安卓)Camera Parameters分析