APP安装时间!(使用adb命令安装)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class InstallTime {

	public static void main(String[] args) {
	String SIBaseVersion = " ";
	//apk名字
	String str="com.netease.newsreader.activity.1508181252.apk";
	  long starTime=System.currentTimeMillis();
	  //APK在PC上的位置(根据具体情况修改)
	  String a = "C:\\XXX\\com.netease.newsreader.activity.1508181252.apk";
	  //abd 安装指令
	  String command1 ="adb install push a";
	  //安装时会出现log,根据关键字确定何时安装,何时结束
	Runtime runtime = Runtime.getRuntime();
	try {
	//执行命令,有一段传输数据的时间,不能计算在内
		Process getSIBaseVersionProcess1  =  runtime.exec(command1);
		BufferedReader bufferedReader = new BufferedReader(
				new InputStreamReader(
						getSIBaseVersionProcess1.getInputStream()));
		 			List<String> tmp = new ArrayList<String>(); 
					while((SIBaseVersion =bufferedReader.readLine())!=null){
						if (isHave(SIBaseVersion, str)) {
							String[] array = SIBaseVersion.split("/");
							for (int i = 0; i < array.length; i++) {
								if (array[i].length() != 0) {
									tmp.add(array[i]);
								}
							}
							// 取list集合中的数据
							String T = tmp.get(4);
						System.out.println(T);
						//开始安装
					if (T.equals(str)) {
						 long endTime=System.currentTimeMillis();
						 long  time1=endTime-starTime;
						 System.out.println(time1);
					}
					 long endTime=System.currentTimeMillis();
					 long  time1=endTime-starTime;
					 //安装成功
					 if (SIBaseVersion.equals("Success")) {
					 //时间
						  long endTime2=System.currentTimeMillis();
						  long time = endTime2-time1;
						  double Time =1.0* time/1000;
						  System.err.println("Time="+Time+" S");
					}
		}
					}
	} catch (Exception e) {
		System.out.println("[Error][Install]" + e.getMessage());
	}

	}
	//判断是否含有指定的内容
	public static boolean isHave(String strs,String s){ 
		for(int i=0;i<strs.length();i++){
			if(strs.indexOf(s)!=-1){;
			return true;
		} 
		}
		return false;
		} 
}


转载于:https://my.oschina.net/MStart/blog/517831

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值