android 9.0系统重启的代码详解

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

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);
发布了262 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/baidu_41666295/article/details/104820946