当前位置:   article > 正文

Android直接执行shell命令_嵌入式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. }
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/733988
推荐阅读
相关标签
  

闽ICP备14008679号