public void runRootCommand(String command){
    Process process = null;
    try{
      process = Runtime.getRuntime().exec(command);
      process.waitFor();
    }catch (Exception e){
      e.printStackTrace();
    }finally{
      try{
        process.destroy();
      }catch (Exception e){
        e.printStackTrace();
      }
    }
  }

 

获取返回的信息

  /*运行command的method*/
  public void runRootCommand(String command){
    Process process = null;
    try{
      process = Runtime.getRuntime().exec(command);
      StringBuffer output = new StringBuffer();
      /*取得返回的信息*/
       
      DataInputStream stdout = new DataInputStream(process.getInputStream());
      
      String line;
      while ((line = stdout.readLine()) != null) {
        output.append(line).append('\n');
      }
      
      process.waitFor();
      /*将返回结果显示于TextView中*/
      mTextView01.setText(output.toString());
    }catch (Exception e){
      mTextView01.setText("权限不足或系统出错");
    }finally{
      try{
        process.destroy();
      }
      catch (Exception e){
        mTextView01.setText("权限不足或系统出错");
      }
    }
  }

 

// 通过指令开启浏览器
runRootCommand("am start -a android.intent.action.VIEW -d http://www.google.com");

 

// 按下按钮后通过指令打电话
runRootCommand("am start -a android.intent.action.CALL -d tel:0912345678");

 

// 计算器(calculator)的启动方法为:
runRootCommand("am start -n com.android.calculator2/.Calculator);

 

// 启动Activity的方法
adb shell
am start -n {包(package)名}/{包名}.{活动(activity)名称}

 

Android Pull Push命令

adb命令下pull的作用是从手机端向电脑端拷文件。 
命令:

//将手机卡中的某个文本文件复制到电脑D盘
adb pull /sdcard/**.txt   D:\                         
adb pull /data/data/com.ifeng.newvideo/databases/ifengVideoV6.db e:/

push的作用和pull正好相反, 是从电脑端向手机复制文件的。下面是例子

adb push d:\lzd.doc /mnt/sdcard/jaj_training/fingerprint/

注意:这些命令都是在adb下用,而不是在shell中用。

 

posted on 2015-04-22 15:20  道无涯  阅读(663)  评论(0编辑  收藏  举报