Shell Script 運行Command

 

  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();
      }
    }
  }

 

獲取返回的信息android

  /*運行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的做用是從手機端向電腦端拷文件。 
命令:shell

//將手機卡中的某個文本文件複製到電腦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中用。app

相關文章
相關標籤/搜索