1:添加sd快捷方式
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的路径
/storage/hdd 是你需要映射的路径
具体方法为:
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卡
二:向串口写数据
String[] cmds = new String[3]; cmd[0] = "sh"; cmd[1] = "-c";
cmd[2] = "echo -en \'\\x11\' > /dev/ttyS3";
x11 你需要向串口写的数据
/dev/ttyS3 端口号
同样调用 execShellCmd(cmds )即可