adb push only if file doesn't exist or has changed - adb

For a program I am using ADB to transfer a file from the computer to mobile phone.
Using adb push overwrites every existent file and thus takes ages to finish.
adb sync does only push the file if it exists on the phone AND contains other data than the local version.
Is there any midway solution? I want the file to be transferred if it doesn't exist or is changed, but not, if it is the same as on the computer. Is there a way to achieve this?

The best way to do this is to first check if the file exists and if it does then sync it and if it does not then push.
Skeleton for a batch script to do this:
FILENAME_RESULT=$(adb shell ls / | tr -d '\015'|grep '^fileName$')
if [ -z "$FILENAME_RESULT" ];
then
REM adb push because the file was not found
else
REM adb sync because the file was found
fi

adb push --sync /local/file /sdcard/remote/file
From adb --help
adb push [--sync] [-zZ] LOCAL... REMOTE copy local files/directories to device --sync: only push files that are newer on the host than the device. -z: enable compression -Z: disable compression

There's a really easy way to do this with adb-sync (https://github.com/google/adb-sync).
adb-sync is a tool to synchronize files between a PC and an Android device using the ADB (Android Debug Bridge).

Related

How to transfer files from Phone to PC using ADB?

Location of pictures:
/storage/sdcard0/pictures/screenshots/
I want to move all the screenshots to below folder in my PC
C:\Users\[username]\Downloads
I have ADB enabled and not rooted my phone.
Help me to use ADB pull.
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 can I Check with adb that there is an external storage Card?

I want to check a file in a sdcard but I have to use ADB.
I made this :
adb shell ls $EXTERNAL_STORAGE
It prompts me a list of directories but it's not my sdCard.
How can I find a file in my sdcard using adb ?
#paralleles. You can use the following adb command below to check if an external storage card exists:
adb shell echo /$EXTERNAL_STORAGE
If the above command executes successfully, you'll see a similar output as below :
Alternatively you can start an adb shell session and traverse the directory so as to find the desired file in your sdcard as follows :
adb shell
cd $EXTERNAL_STORAGE
If the above commands executes successfully, you'll see a similar output as below (depending on the files/folders in your SdCard):

Android Things: take a screenshot

How do you take a screenshot via ADB for Android Things? I have tried:
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
and
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
I couldn't make screepcap work in Android Things Developer Preview. The command results in a 0-size file.
That said, I recommend the following two options: either use the framebuffer or record a video (screenrecord seems to work) and convert it to an image later on by proper tool. I'll consider the first option, so the steps would be:
Pull the framebuffer to the host machine. Note that you need to start adbd as root in order to pass a permission check:
adb root
adb pull /dev/graphics/fb0 screenshot
Convert the raw binary to image by the tool you prefer. I'm using ffmpeg. The command below might not work for you due to different screen resolution or pixel format. If so, make proper changes.
ffmpeg -f rawvideo -pix_fmt rgb565 -s 800x480 -i screenshot screenshot.png
Seems, because of old limited OpenGL version in Android Things, described by Tatsuhiko Arai here there is no possibility to get screenshot via ADB, but You can record video (e.g. from Android Studio, or via ADB commands) and than grab frame from it, for example via ffmpeg:
ffmpeg -i device-2017-01-23-193539.mp4 -r 1 screen-%04d.png
where device-2017-01-23-193539.mp4 - name of recorded (via Android Studio) file .
I've tried exactly this code with a little bit change like below (but no matter) and it works well. The image is in my platform-tools directory now.
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png screen.png
adb shell rm /sdcard/screen.png

Call command from exe in bat file

I am currently developing a android app and I am debugging wireless.
Every time I want to do this, I need to open the cmd in a specific direction and type:
adb
adb connect 'some ip'
adb is a exe and adb connect is some command in adb.exe
I was trying to write a simple bat file for this and I found this on the internet:
START C:\Andriod\adb.EXE
As you know, this only starts the adb.
I could not find how to call this command, propbably because I do not know the correct name for it. Can someone help me?
Use CALL command like this in batch:
#echo off
call C:\Andriod\adb.EXE
adb -s [yourdeviceserialnumberhere] shell
adb connect {ip:host}
http://www.droidforums.net/forum/android-hacks-help/6865-how-use-adb-all-commands-options.html

Adb pull command from a device to pc

If there is a space in the directory in the adb pull operation, say
adb pull data/tombstones "c:/Program files/myApp"
is any other way to do it besides adding quotation mark on it "c://Program Files/myApp" to accomplish the same thing?
You can try using the short name of the folder. for program files it is progra~1.
you can see short name with dir /x.
I've never tried it with ADB, but I think it should work.

Resources