1.首先項目結構
2.其次,核心代碼
public static Process exec(String value) throws IOException {
String path = System.getProperty("user.dir");
return java.lang.Runtime.getRuntime().exec(path+"/adb/adb.exe " + value);
}
2.1下載ADB程序到PC,並放入項目目錄下 的adb文件夾內
2.2創建指向adb目標的指令類方便開發
2.3創建一個臨時文件夾tem,用於保存從android中pull出的文件
2.3.1 工具類代碼
public class Runtime {
public static Process exec(String value) throws IOException {
String path = System.getProperty("user.dir");
return java.lang.Runtime.getRuntime().exec(path+"/adb/adb.exe " + value);
}
}
2.3.2 導入文件代碼
public static void pull(String device) {
try {
Runtime.exec("-s "+device+" pull /usrapp/num.txt " +System.getProperty("user.dir")+"/tem/num.txt");
Runtime.exec("-s "+device+" pull /usrapp/ipconfig " +System.getProperty("user.dir")+"/tem/ipconfig.properties");
} catch (IOException e) {
e.printStackTrace();
}
}
2.3.3 導入文件代碼
public static void push(String device) {
try {
Runtime.exec("-s "+device+" push " +System.getProperty("user.dir")+"/tem/ipconfig.properties "+"/usrapp/ipconfig");
Runtime.exec("-s "+device+" push " +System.getProperty("user.dir")+"/tem/num.txt "+"/usrapp/");
} catch (IOException e) {
e.printStackTrace();
}
}