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 AVD屏幕显示问题。。急求 activity中创建一个dialog,在dialog中如何调用activity的函数? ItemizedOverlay中怎么自定义图标 Android如何访问电脑上的服务器 android 利用ksoap2参数传递 向各位大侠请教两个android问题! android 中的页面显示的分辨率 请教画面渲染的问题 Android Studio,无法创建新工程 仿微信的底部图片颜色渐变问题 急,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");
};