Reboot programmatically Android Things

前端 未结 4 1480
忘掉有多难
忘掉有多难 2020-12-19 20:38

I want to use this code in order to reboot my RPI3 running Android Things:

public static void Reboot()
{
    try {
        Process proc = R         


        
4条回答
  •  情书的邮戳
    2020-12-19 20:58

    You need a root access.

    public static void runCmd(String cmd) {
        DataOutputStream os;
        try {
            Process process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd + "\n");
            os.writeBytes("exit\n");
            os.flush();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    Then you can run any commands that require root access like this: runCmd("reboot");

提交回复
热议问题