当前位置:   article > 正文

Android直接执行shell命令

Android直接执行shell命令
  1. public void shellExec() {
  2. Runtime mRuntime = Runtime.getRuntime();
  3. try {
  4. //Process中封装了返回的结果和执行错误的结果
  5. Process mProcess = mRuntime.exec("adb version");
  6. BufferedReader mReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
  7. StringBuffer mRespBuff = new StringBuffer();
  8. char[] buff = new char[1024];
  9. int ch = 0;
  10. while ((ch = mReader.read(buff)) != -1) {
  11. mRespBuff.append(buff, 0, ch);
  12. }
  13. mReader.close();
  14. System.out.print(mRespBuff.toString());
  15. } catch (IOException e) {
  16. // TODO Auto-generated catch block
  17. e.printStackTrace();
  18. }
  19. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/160702
推荐阅读
相关标签
  

闽ICP备14008679号