Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

java - Reboot programmatically Android Things

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

public static void Reboot()
{
    try {
        Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot"});
        proc.waitFor();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

I get the following error:

java.io.IOException: Cannot run program "su": error=13, Permission denied

I add to the manifest all the permission

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SET_TIME_ZONE"/>
<uses-permission android:name="android.permission.SHUTDOWN"/>

Am I missing something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can now do a reboot using:

https://developer.android.com/things/reference/com/google/android/things/devicemanagement/DeviceManager.html

Example

 public class SomeActivity extends Activity {

     void doReboot() {
         DeviceManager.getInstance().reboot();
     }

     void doFactoryReset() {
         boolean wipeExternalCard = true;
         DeviceManager.getInstance().factoryReset(wipeExternalCard);
     }
  }

You need the com.google.android.things.permission.REBOOT permission


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...