android程序打开ttyUSB0无读权限

zjg2011zjg 2012-02-21 03:27:05


android下的程序想要读ttyUSB0,但是发现设备插入后,ttyUSB0的权限为crw-------,有高手出招吗?网上的方法试过在java代码中添加exec(“su”)获取root权限,但是执行不成功,用adb shell登陆时在app用户下不允许执行su命令。求高手指点!
...全文
726 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqhrs232 2012-02-24
  • 打赏
  • 举报
回复
用SYSTEM命令试试,要不自己修改INIT.RC文件再去自己编译IMAGE
gotime_wxb2008 2012-02-24
  • 打赏
  • 举报
回复
看看是否是root权限问题,如果是权限问题简单 chmod 777即可;如果不是root权限,则需要厂家在对应的设备文件中,增加设备驱动,并相应的改变权限;这样就可以再以后的USB转串口中调用了!
zjg2011zjg 2012-02-23
  • 打赏
  • 举报
回复
不给力啊,这个问题打2010年就提出了,木有办法
zjg2011zjg 2012-02-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zjg2011zjg 的回复:]

引用 2 楼 taotaoqi82 的回复:

代码我看看



public boolean runRootCommand(String command) {
Log.d("run into runRootCommand ***", "siiiiiiiiiiiiiiiiiiii");
Process process = null;
DataOutputStream os = ……
[/Quote]



这俩文件都是没权限去修改啊
lbmygf 2012-02-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zjg2011zjg 的回复:]

引用 2 楼 taotaoqi82 的回复:

代码我看看



public boolean runRootCommand(String command) {
Log.d("run into runRootCommand ***", "siiiiiiiiiiiiiiiiiiii");
Process process = null;
DataOutputStream os = ……
[/Quote]


这样没用的 ,你当前进程并没有权限修改串口权限
lbmygf 2012-02-22
  • 打赏
  • 举报
回复
在init.rc中修改,或者在内核usb驱动中把它改过来
zjg2011zjg 2012-02-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 taotaoqi82 的回复:]

代码我看看
[/Quote]


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");
};
zjg2011zjg 2012-02-21
  • 打赏
  • 举报
回复
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");
};
taotaoqi82 2012-02-21
  • 打赏
  • 举报
回复
代码我看看
zjg2011zjg 2012-02-21
  • 打赏
  • 举报
回复
咋个没人回呢?各位大大们,跪求啦

80,357

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧