android程序打开ttyUSB0无读权限 android下的程序想要读ttyUSB0,但是发现设备插入后,ttyUSB0的权限为crw-------,有高手出招吗?网上的方法试过在java代码中添加exec(“su”)获取root权限,但是执行不成功,用adb shell登陆时在app用户下不允许执行su命令。求高手指点! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public boolean runRootCommand(String command) { Log.d("run into runRootCommand ***", "siiiiiiiiiiiiiiiiiiii"); Process process = null; DataOutputStream os = null; try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command+"\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage()); return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { // nothing } } return true; } if(!runRootCommand("chmod 666 /dev/ttyUSB0")){ runRootCommand("chmod 666 /dev/ttyUSB1"); }; public boolean runRootCommand(String command) {Log.d("run into runRootCommand ***", "siiiiiiiiiiiiiiiiiiii");Process process = null;DataOutputStream os = null;try {process = Runtime.getRuntime().exec("su");os = new DataOutputStream(process.getOutputStream());os.writeBytes(command+"\n");os.writeBytes("exit\n");os.flush();process.waitFor();} catch (Exception e) {Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage());return false;}finally {try {if (os != null) {os.close();}process.destroy();} catch (Exception e) {// nothing}}return true;}if(!runRootCommand("chmod 666 /dev/ttyUSB0")){runRootCommand("chmod 666 /dev/ttyUSB1");}; 在init.rc中修改,或者在内核usb驱动中把它改过来 看看是否是root权限问题,如果是权限问题简单 chmod 777即可;如果不是root权限,则需要厂家在对应的设备文件中,增加设备驱动,并相应的改变权限;这样就可以再以后的USB转串口中调用了! 用SYSTEM命令试试,要不自己修改INIT.RC文件再去自己编译IMAGE android程序报错之后,怎么关闭应用程序啊 S5PV210上跑ICS的显卡(PVR)问题请教 求助android画折线图问题 请教一下 为什么我的setListAdapter(...)总是出错 而源码的确是这样的 关于listview的一些问题 Android 2.3 如何编译.a的库文件 如何实现图片的高效移动 android 手机RAM,Flash ROM、内存概念的困惑,看你是否真的明白 请教:如微信公共平台新闻信息这样的样式框如何处理 客户端如何加载服务端的图片 急,xt910无法进行真机调试 小白求救:开发网站或者oa等网站或系统的移动版 需要改程序吗》?》?
Log.d("run into runRootCommand ***", "siiiiiiiiiiiiiiiiiiii");
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage());
return false;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// nothing
}
}
return true;
}
if(!runRootCommand("chmod 666 /dev/ttyUSB0")){
runRootCommand("chmod 666 /dev/ttyUSB1");
};
Log.d("run into runRootCommand ***", "siiiiiiiiiiiiiiiiiiii");
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage());
return false;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// nothing
}
}
return true;
}
if(!runRootCommand("chmod 666 /dev/ttyUSB0")){
runRootCommand("chmod 666 /dev/ttyUSB1");
};