简体   繁体   中英

Is there a way to reboot an Android device using flutter Process.run()?

I want to create an app to restart my phone. My motivation for this is because my power button is broken. This is my current code (stderr doesn't print to console by default, only exceptions do):

  _reboot() {
    Process.run('reboot',['-p']).then((ProcessResult results) {
      print("stdout: \n" + results.stdout + "stderr:\n" + results.stderr);
    });
  }

Which outputs the error:

I/flutter (24139): stdout: 
I/flutter (24139): stderr:
I/flutter (24139): shutdown: Permission denied

So I have two questions:

  1. Can I run this command as a superuser? I checked, and the su and sudo commands don't exist on my Android version.
  2. If I root my phone, would this command work?

I think you need Root. Can you try?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM