我有一段代码适用于 Android 4.4.2 及以下 Android 版本,但不适用于棒棒糖。
我知道当棒棒糖问世时,很多需要ROOT权限的应用程序停止工作,但我不知道他们是如何解决它的问题的。
这是代码:
System.out.println("Running tool");
Process p = Runtime.getRuntime().exec("su");
os = p.getOutputStream();
os.write((context.getFilesDir().getAbsolutePath() + "/tool " + context.getFilesDir().getAbsolutePath() + "\n").getBytes());
os.write("exit\n".getBytes());
p.waitFor();
所有测试的手机都是ROOT。
在行中:
os.write((context.getFilesDir().getAbsolutePath() + "/tool " + context.getFilesDir().getAbsolutePath() + "\n").getBytes());
抛出异常:
02-15 23:02:23.917 10130-10130/com.test I/System.out? Running tool
02-15 23:02:24.680 10130-10130/com.test W/System.err? java.io.IOException: write failed: EPIPE (Broken pipe)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at libcore.io.IoBridge.write(IoBridge.java:502)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at java.io.FileOutputStream.write(FileOutputStream.java:186)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at java.io.OutputStream.write(OutputStream.java:82)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at com.secondary_test.MainActivity.onClick(MainActivity.java:86)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at com.secondary_test.Principal.getPass(Principal.java:25)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at com.test.Main.onCreate(Main.java:36)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at android.app.Activity.performCreate(Activity.java:5933)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at android.app.ActivityThread.access$900(ActivityThread.java:147)
02-15 23:02:24.681 10130-10130/com.test W/System.err? at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at android.os.Handler.dispatchMessage(Handler.java:102)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at android.os.Looper.loop(Looper.java:135)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at android.app.ActivityThread.main(ActivityThread.java:5256)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at java.lang.reflect.Method.invoke(Native Method)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at java.lang.reflect.Method.invoke(Method.java:372)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
02-15 23:02:24.682 10130-10130/com.test W/System.err? at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
02-15 23:02:24.682 10130-10130/com.test W/System.err? Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
02-15 23:02:24.690 10130-10130/com.test W/System.err? at libcore.io.Posix.writeBytes(Native Method)
02-15 23:02:24.691 10130-10130/com.test W/System.err? at libcore.io.Posix.write(Posix.java:223)
02-15 23:02:24.691 10130-10130/com.test W/System.err? at libcore.io.BlockGuardOs.write(BlockGuardOs.java:313)
02-15 23:02:24.691 10130-10130/com.test W/System.err? at libcore.io.IoBridge.write(IoBridge.java:497)
有人遇到过这个问题或知道如何解决吗?
谢谢大家。