In the manifest file, add android:sharedUserId= “android.uid.system”, and have the system signature.

The first way

Use the ADB shell command directly and call the reboot command to shut it down

try { Runtime.getRuntime().exec("reboot -p"); } catch (IOException e) {e.printStackTrace(); }Copy the code

The second way

Call the shutdown method in PowerManage, but that method is a hidden API that can be called by reflection, as follows:

try { PowerManager pManager = (PowerManager) VfiServiceApp.getContext().getSystemService(Context.POWER_SERVICE); if (pManager ! = null) { Method method = pManager.getClass().getMethod("shutdown", boolean.class, String.class, boolean.class); method.invoke(pManager, false, null, false); } } catch (Exception e) { e.printStackTrace(); }Copy the code

The first type directly black screen, the second type can set the dialog box, if both are false, the shutdown dialog box will appear directly, not directly black screen