行是知之始,知是行之成。这篇文章主要讲述Android Runtime.getRuntime().exec相关的知识,希望能为你提供帮助。
try { // Executes the command. Process process = Runtime.getRuntime().exec(cmd); // NOTE: You can write to stdin of the command using // process.getOutputStream(). BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); // Waits for the command to finish. process.waitFor(); return output.toString(); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }
【Android Runtime.getRuntime().exec】 String mProjectName = doCommand("cat /proc/version").trim();
Log.d(TAG, "mProjectName =" + mProjectName);
推荐阅读
- Android6.0------权限申请~easypermissions
- Android App压力测试之Monkey
- App性能优化之内存优化
- Android基础系列合集
- WPF入门教程系列三——Application介绍(续)
- 完整Android开发基础入门博客专栏
- WPF入门教程系列二——Application介绍
- WPF入门教程系列七——布局之WrapPanel与StackPanel
- Android Studio环境解读