android下的程序想要读ttyUSB0,但是发现设备插入后,ttyUSB0的权限为crw-------,有高手出招吗?网上的方法试过在java代码中添加exec(“su”)获取root权限,但是执行不成功,用adb shell登陆时在app用户下不允许执行su命令。求高手指点!

解决方案 »

  1.   

    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");
    };
      

  2.   

    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");
    };
      

  3.   

    在init.rc中修改,或者在内核usb驱动中把它改过来
      

  4.   

    看看是否是root权限问题,如果是权限问题简单 chmod 777即可;如果不是root权限,则需要厂家在对应的设备文件中,增加设备驱动,并相应的改变权限;这样就可以再以后的USB转串口中调用了!
      

  5.   

    用SYSTEM命令试试,要不自己修改INIT.RC文件再去自己编译IMAGE