Android: Adb Pull File on Desktop

Android: adb pull file on desktop

Use a fully-qualified path to the desktop (e.g., /home/mmurphy/Desktop).

Example: adb pull sdcard/log.txt /home/mmurphy/Desktop

adb pull file in a specific folder of Pc

Always use double quotes("") for local paths. use it like this:

cmd = "adb pull /sdcard/screen.png \"C:\\Users\\xxx\\Desktop\\prova\\screen.png\"";

How do I adb pull ALL files of a folder present in SD Card

Single File/Folder using pull:

adb pull "/sdcard/Folder1"

Output:

adb pull "/sdcard/Folder1"
pull: building file list...
pull: /sdcard/Folder1/image1.jpg -> ./image1.jpg
pull: /sdcard/Folder1/image2.jpg -> ./image2.jpg
pull: /sdcard/Folder1/image3.jpg -> ./image3.jpg
3 files pulled. 0 files skipped.

Specific Files/Folders using find from BusyBox:

adb shell find "/sdcard/Folder1" -iname "*.jpg" | tr -d '\015' | while read line; do adb pull "$line"; done;

Here is an explanation:

adb shell find "/sdcard/Folder1" - use the find command, use the top folder
-iname "*.jpg" - filter the output to only *.jpg files
| - passes data(output) from one command to another
tr -d '\015' - explained here: http://stackoverflow.com/questions/9664086/bash-is-removing-commands-in-while
while read line; - while loop to read input of previous commands
do adb pull "$line"; done; - pull the files into the current running directory, finish. The quotation marks around $line are required to work with filenames containing spaces.

The scripts will start in the top folder and recursively go down and find all the "*.jpg" files and pull them from your phone to the current directory.

How to transfer files from Phone to PC using ADB?

Use the following command:

adb pull /storage/sdcard0/pictures/screenshots/ C:\Users\<username>\Downloads

You will find the folder named 'screenshots' at the location C:\Users\<username>\Downloads

How to push a file from computer to /data/.../databases/ using adb command?

There is no simple command for uploading the file. What Android Studio does when uploading a file using Device File Explorer is this:

  1. Upload the file via adb push to /data/local/tmp/<random file name>
  2. Execute adb shell run-as com.myapp sh -c 'cp /data/local/tmp/<random file name> /data/data/com.myapp/<path>/<final file-name>'
  3. Delete the temp file via adb shell rm /data/local/tmp/<random file name>
  4. Get the updated view for Device File Explorer using adb shell run-as com.myapp sh -c 'ls -al /data/data/com.myapp/<path>/'

I discovered this by capturing the adb traffic on TCP port 5027 using Wireshark. An interesting detail is that each command executed using adb shell command uses the form <command-to-be executed in adb shell> || echo ERR-ERR-ERR-ERR

How to copy file using adb to android directory accessible from PC

Try to use /sdcard/. Although it is strongly discouraged to do this in code. It seems to be the only way with adb :

$ adb push somefile /storage/emulated/0/somefile
[100%] /storage/emulated/0/somefile
adb: error: failed to copy 'somefile' to '/storage/emulated/0/somefile': Read-only file system

$ adb push somefile /sdcard/somefile
[100%] /sdcard/somefile

By the way, on my device they don't have the same value : Environment.getExternalStorage() points to /storage/emulated/0/ while /sdcard points to /storage/emulated/legacy.

How can we copy all the apps from android(adb) to PC using Batch scripting?

The batch file is not working as expected because of delayed expansion is used only for some, but not all environment variable references inside the FOR command block. Only the environment variable input can be referenced with %input% inside the command block as it is the only environment variable defined outside the command block and not modified inside the command block. All other environment variables are defined/modified inside the command block and referenced inside the command block. For that reason all environment variables except input must be referenced with using ! instead of %.

However, the usage of environment variables is not needed at all for this task.

@echo off
setlocal EnableExtensions DisableDelayedExpansion
if not defined input set "input=1"
set "count=0"
if exist myapps.txt for /F "tokens=2 delims=:" %%I in (myapps.txt) do (
echo Getting path of app "%%I" ...
for /F "tokens=2 delims=:" %%J in ('adb.exe shell pm path "%%I" 2^>nul') do (
echo Path of app %%I is: "%%J"
rem Creating new folder for each app.
mkdir "apps_%input%\%%I" 2>nul
if exist "apps_%input%\%%I\" (
rem Pulling app from Android to PC.
echo Pulling app "%%I" to "apps_%input%\%%I" ...
adb.exe pull "%%J" "apps_%input%\%%I"
set /A count+=1
) else echo ERROR: Failed to create directory: "apps_%input%\%%I\"
)
)
if %count% == 1 (set "PluralS=") else set "PluralS=s"
echo Pulled %count% app%PluralS% from Android to PC.
endlocal

The outer FOR reads one line after the other from myapps.txt. Each line is split up into substrings using the colon as delimiter because of option delims=:. The first colon delimited substring is always package which is of no interest for this task. Therefore the option tokens=2 is used to assign the second substring like com.flipkart.android to the specified and case-sensitive loop variable I.

The inner FOR loop starts in background one more command process with %ComSpec% /c and the command line in the parentheses appended as additional argument. The output of adb to handle STDOUT of the background command process is captured by FOR and processed line by line after started cmd.exe closed itself after adb terminated itself.

The single line output by adb is again split up into substrings using colon as delimiter with assigning again just the second substring to specified loop variable J.

Next a subdirectory is created with application name as directory name with redirecting the error message output on directory already existing or failed to create from handle STDERR to device NUL to suppress it.

Then an existence check for the just created directory is made to verify if it really exists and if this is the case the application is pulled from Android device to PC.

The help output on running cmd /? in a command prompt window explains on last page that a file name (or any other argument string) containing a space or of these characters &()[]{}^=;!'+,`~ must be enclosed in double quotes. For that reason all argument strings referencing the value assigned currently to the loop variables I (app name) and J (app path) are enclosed in ".

All echo command lines and the last if condition can be removed as they are just for getting some progress information during execution of the batch file.

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • echo /?
  • endlocal /?
  • for /?
  • if /?
  • mkdir /?
  • rem /?
  • set /?
  • setlocal /?

Read the Microsoft article about Using command redirection operators for an explanation of 2>nul. The redirection operator > must be escaped with caret character ^ on FOR command line to be interpreted as literal character when Windows command interpreter processes this command line before executing command FOR which executes the embedded adb command line with using a separate command process started in background.

ADB PULL Command

I found a workaround for my problem, posting code below,

import java.io.*;
public class TestModule {

public static void main(String[] args) throws IOException,InterruptedException {

String line = "null";
String cmd = "adb pull /storage/sdcard1/Android/data/files /Users/sbc/Desktop";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while ((line=buf.readLine())!=null) {
System.out.println(line);
}
}
}

In place of accessing the folder with the space, I accessed it's parent folder
/storage/sdcard1/Android/data/files/test\ Information/<--current folder with space
/storage/sdcard1/Android/data/files<--Parent Folder.

Now adb downloads all the contents of "Parent Folder"



Related Topics



Leave a reply



Submit