Restart android device programmatically

半世苍凉 提交于 2019-11-27 19:53:44

The permission you required is not related to your reboot method, as your method requires a rooted phone (with su). To reboot the phone, require the permission as you did, but call PowerManager#reboot.

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
pm.reboot(null);

On API 24 if your app is the device owner app you can call: devicePolicyManager.reboot(yourAdminComponent)

See docs here

Try this...

try {
      Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
      proc.waitFor();
         } catch (Exception ex) {
                Log.i(TAG, "Could not reboot", ex);
      }

Add permission reboot

KishuDroid

You cannot do a reboot from an ordinary SDK application. Only applications signed with the system firmware signing key can do this. Copied from this answer,

Programmatically switching off Android phone

You need the system key to sign your app. See this post for details;

How to compile Android Application with system permissions

After long struggle i found working solution.

If your system is used serial port then execute below command,

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});

if use normal port then excure below command

Runtime.getRuntime().exec(new String[]{"/system/xbin/su","-c","reboot now"});

difference is only /bin and /xbin

so can code like if first command throw exception then execute second.

You can use the legendary LibSuperUser library.

Write this simple code:

Shell.SU.run("reboot");

You are doing <permission ... />. You need to do <USES-permission ... />

The caps are not needed, it was just to emphasise it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!