首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android java 获得root权限后,执行adb shell命令的有关问题

2012-08-15 
android java 获得root权限后,执行adb shell命令的问题android java 成功获得root权限后(log信息可知), 执

android java 获得root权限后,执行adb shell命令的问题
android java 成功获得root权限后(log信息可知), 执行adb shell命令时, 出错, 是什么地方的问题呢?


Runtime ex = Runtime.getRuntime(); 
String cmdBecomeSu = "su"; 
String script = "busybox chmod a+rw /dev/input/event1"; 
String script1 = "busybox sendevent /dev/input/event1 1 116 1"; 
String script2 = "busybox sendevent /dev/input/event1 0 0 0"; 
String script3 = "busybox sendevent /dev/input/event1 1 116 0"; 
String script4 = "busybox sendevent /dev/input/event1 0 0 0"; 

try{ 
java.lang.Process runsum = ex.exec(cmdBecomeSu); 
int exitVal = 0; 
final OutputStreamWriter out = new OutputStreamWriter(runsum.getOutputStream()); 

// Write the script to be executed 
out.write(script); 

// Ensure that the last character is an "enter" 
out.write("\n"); 
out.flush(); 

// Terminate the "su" process 
out.write("exit\n"); 
out.flush(); 

exitVal = runsum.waitFor(); 
if (exitVal == 0) { 
Log.e("Debug", "...Successfully to su"); 
}

//*********************************************
out.write(script1); 

// Ensure that the last character is an "enter" 
out.write("\n"); 
out.flush(); 

// Terminate the "su" process 
out.write("exit\n"); 
out.flush(); 
//*********************************************

//*********************************************
out.write(script2); 

// Ensure that the last character is an "enter" 
out.write("\n"); 
out.flush(); 

// Terminate the "su" process 
out.write("exit\n"); 
out.flush(); 
//*********************************************

//*********************************************
out.write(script3); 

// Ensure that the last character is an "enter" 
out.write("\n"); 
out.flush(); 

// Terminate the "su" process 
out.write("exit\n"); 
out.flush(); 
//*********************************************

//*********************************************
out.write(script4); 

// Ensure that the last character is an "enter" 
out.write("\n"); 
out.flush(); 

// Terminate the "su" process 
out.write("exit\n"); 
out.flush(); 
//*********************************************



} catch ( Exception e){ 
Log.e("Debug", "Fails to su"); 



[解决办法]

Log.e("Debug", "Fails to su");
前面加上
e.printStackTrace();

看一下具体出错提示
[解决办法]

探讨
这些参数应如何写呢?

String script1 = "busybox sendevent /dev/input/event1 1 116 1";
String script2 = "busybox sendevent /dev/input/event1 0 0 0";
String script3 = "busybox sendevent /dev/input/event1 ……

热点排行