1:添加sd快捷方式java
String oldPath = file.getPath(); Slog.e("m_tag", "oldPath=" + oldPath); String cmd = "ln -s " + oldPath + " /storage/hdd"; String[] cmds = {"su", "-c", cmd}; Slog.e("m_tag", "cmd=" + cmd); execShellCmd(cmds);
oldPath 是sd的路径app
/storage/hdd 是你须要映射的路径ui
具体方法为:spa
private String execShellCmd(String[] cmds) { Runtime runtime = Runtime.getRuntime(); try { java.lang.Process p = runtime.exec(cmds); if (p.waitFor() != 0) { Slog.e(TAG, "exit value = " + p.exitValue()); } BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder sb = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { sb.append(line + "-"); } Slog.e(TAG, "serial port back data:" + sb.toString()); return sb.toString(); } catch (Exception e) { Slog.e(TAG, "execShellCmd error:" + e.toString()); e.printStackTrace(); } return "null"; }
执行完后,经过路径/storage/hdd 也可找到sd卡get
二:向串口写数据cmd
String[] cmds = new String[3]; cmd[0] = "sh"; cmd[1] = "-c";
cmd[2] = "echo -en \'\\x11\' > /dev/ttyS3";
x11 你须要向串口写的数据it
/dev/ttyS3 端口号io
一样调用 execShellCmd(cmds )便可file