开发者

android runtime command problem

i'm trying to reboot my android device (doing android porting) for test.

my code :

try {
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("reboot");

            InputStream is = proc.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;

            while ((line = br.readLine()) != null) {
                Log.i("runtime","line : " + line);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

but the device didn't reboot itself.

if i change the command to

Runtime rt = Runtime.g开发者_StackOverflowetRuntime();
Process proc = rt.exec("ls");

it ran fine , show all dir.

and when i input "reboot" in adb shell , it also worked. why???

reboot is just one of toolbox commands, I also run other command which can work from shell. But, none of them can work from rt.exec except 'ls'. Could some one tell me how to make it works from android runtime ? Thanks


you can't do this on non-rooted phones:

How to boot android phone programmatically?


Refer Runtime.exec() : Reboot in Android ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜