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

 

获取返回的信息

  /*运行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中用。

 

转载于:https://www.cnblogs.com/huangzx/p/4447578.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值