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