I'm trying to create a method that will pull a file from an Android device into a local path on my machine.
I'm using the pullFile method from com.android.ddmlib and I'm getting this error:
02:45:59 E/ddms: Failed to open local file C:\Users\amiyahav\Desktop\PullFile for writing, Reason: java.io.FileNotFoundException: C:\Users\amiyahav\Desktop\PullFile (Access is denied)
02:45:59 E/Device: Error during Sync: Writing local file failed!
This is my function:
public static void pullFile(@SuppressWarnings("rawtypes") AppiumDriver driver, String remote, String local) throws TimeoutException, FailureException, AdbCommandRejectedException, SyncException, IOException {
AndroidDebugBridge.init(false);
AndroidDebugBridge adb = AndroidDebugBridge.createBridge();
String deviceUdid = (String) driver.getCapabilities().getCapability(MobileCapabilityType.UDID);
long startTime = System.currentTimeMillis();
while (!adb.isConnected() || !adb.hasInitialDeviceList()) {
if (System.currentTimeMillis() - startTime >= 20000)
throw new TimeoutException("Error occurred while loading devices list");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new FailureException("Action execution interrupted",e);
}
}
adb.getDevices()[0].pullFile(remote, local);
}
This is the JUnit test:
@Test
public void runPullFileAndroid() throws Exception {
String remote = "/data/hw_init/product/media/Pre-loaded/Music/Dream_It_Possible.flac";
String local = "C:\\Users\\amiyahav\\Desktop\\PullFile";
AndroidDriver driver = runner.getDriver();
try {
ADBHelper.pullFile(driver, remote, local);
} catch (Exception e) {
throw new FailureException("Failed running ADB shell command",e);
}
}
Any help will be appreciated!