没有直接的API。我们有一个类似的场景,用户从桌面客户端(在我们的例子中基于 Java Swing)同步内容(即数据库),该客户端手动使用 adb,到目前为止它工作正常。
在我们的 java 客户端中,我们会调用:
private static final String ADB_PUSH = "\"" + Utility.getWorkDir() + File.separator + "adb\" -s %s push \"%s\" %s";
/**
* Pushes a file to a connected device via ADB
* @param deviceId Device serial number
* @param from Path of source file (on PC)
* @param to Path of file destination (on device)
*/
public static void push(String deviceId, String from, String to) {
try {
String cmd = String.format(ADB_PUSH, deviceId, from, to);
System.out.println("adb push: " + cmd);
Process p = Runtime.getRuntime().exec(cmd);
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println("adb: " + line);
}
} catch (IOException e) {
System.out.println(e);
}
}