adb screencap creates corrupted file [duplicate] - android

This question already has answers here:
Read binary stdout data like screencap data from adb shell?
(19 answers)
Closed 5 years ago.
I'm trying to take a screenshot on my Android device with adb. I'm able to connect to my device and execute the commands, but the result is a corrupted file.
Im on a Ubuntu 14.04 system.
My device is a Nexus 6 with Android 6.0 Beta on it.
I do the following:
adb shell screencap -p | sed 's/\r$//' > screenshot.png
I tried this as well:
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
I know it's also possible to use the pull method. But I prefer this one because it's faster.

hey this is how i screencap our app, though i am using win7
adb shell screencap /sdcard/screen.png
also, i don't know what's that weird tags. when you use android's native screen capture command, android saves it on Pictures/Screenshot if i remember it right. i am using a Samsung Galaxy Tab 3.

Related

Android Studio see device as null [duplicate]

This question already has answers here:
set up device for development (???????????? no permissions)
(30 answers)
Closed 4 years ago.
On Ubuntu Android Studio shows devices as null.
Every time I turn on my laptop, I need to run the following console commands to add permissions:
./adb devices
./adb kill-server
sudo ./adb devices
Enter my password and then repeat:
./adb kill-server
./adb devices
Note I'm using a xiaomi phone.
Is there a way to get around this permission issues so I don't have to do it ever time.
Anyway, what I did to solve this problem.
Defined in what cases I need to run these commands. For most ubuntu users there is a home folder (hidden file .bashrc).
In which you can record the launch of these commands. But these commands will be triggered when you enter the bash command in the console.
Since I have a shell .zshrc then I did the following:
open console: gedit .zshrc
When the file opens, add the following line:
./.add_device_permissions.sh
After or before, we need to create this file: .add_device_permissions.sh in which we write the following:
#!/bin/bash
# Add permissions for Xiaomi Redmi Note 5
ADB="/home/vadimm/Android/Sdk/platform-tools/adb"
$ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
Also we need create .permissions_redmi_note where we need to hardcode our password.
Not to add to the file .zshrc unnecessary we can specify the path when starting the system itself: Startup Applications Preferences
Where we press on "Add" and write our command: /home/vadimm/.add_device_permissions.sh

Using ADB to capture the screen [duplicate]

This question already has answers here:
Read binary stdout data like screencap data from adb shell?
(19 answers)
Closed 6 years ago.
I'm trying to get a screenshot of the phone screen as fast as possible.
Currently, I am doing:
adb shell screencap -p /sdcard/screencap.png && adb pull /sdcard/screencap.png
However it is too slow and takes up to 3 seconds.
Is there any better way to do this? I intend to use this function with an unrooted phone.
Also what are the different arguments I can use for screencap?
Thanks.
EDIT (extra information): I intend to use this method to be able to get a live feed of the screen onto my pc. The current method works however it is too slow. I can't use adb shell screenrecord because I won't be able to access the video file while it is being recorded.
To save to a file on Windows, OSX and Linux
adb exec-out screencap -p > screen.png
To copy to clipboard on Linux use
adb exec-out screencap -p | xclip -t image/png
https://stackoverflow.com/a/37191719/75579 answer stopped working for me in Android 7 somehow. So I have to do it the manual way, so I want to share it.
How to install
Put this snippet of code in your ~/.bash_profile or ~/.profile file:
snap_screen() {
if [ $# -eq 0 ]
then
name="screenshot.png"
else
name="$1.png"
fi
adb shell screencap -p /sdcard/$name
adb pull /sdcard/$name
adb shell rm /sdcard/$name
curr_dir=pwd
echo "save to `pwd`/$name"
}
Run source ~/.bash_profile or source ~/.profile command,
How to use
Usage without specifying filename:
$ snap_screen
11272 KB/s (256237 bytes in 0.022s)
Saved to /Users/worker8/desktop/screenshot.png
Usage with a filename:
$ snap_screen mega_screen_capture
11272 KB/s (256237 bytes in 0.022s)
Saved to /Users/worker8/desktop/mega_screen_capture.png
Hope it helps!
** This will not work if multiple devices are plugged in
To start recording your device’s screen, run the following command:
adb shell screenrecord /sdcard/example.mp4
This command will start recording your device’s screen using the default settings and save the resulting video to a file at /sdcard/example.mp4 file on your device.
When you’re done recording, press Ctrl+C in the Command Prompt window to stop the screen recording. You can then find the screen recording file at the location you specified. Note that the screen recording is saved to your device’s internal storage, not to your computer.
The default settings are to use your device’s standard screen resolution, encode the video at a bitrate of 4Mbps, and set the maximum screen recording time to 180 seconds. For more information about the command-line options you can use, run the following command:
adb shell screenrecord --help
This works without rooting the device. Hope this helps.
You can read the binary from stdout instead of saving the png to the sdcard and then pulling it:
adb shell screencap -p | sed 's|\r$||' > screenshot.png
This should save a little time, but not much.
source: Read binary stdout data from adb shell?
Using some of the knowledge from this and a couple of other posts, I found the method that worked the best for me was to:
adb shell 'stty raw; screencap -p'
I have posted a very simple Python script on GitHub that essentially mirrors the screen of a device connected over ADB:
https://github.com/baitisj/android_screen_mirror
Sorry to tell you screencap just a simple command, only accept few arguments, but none of them can save time for you, here is the -h help output.
$ adb shell screencap -h
usage: screencap [-hp] [-d display-id] [FILENAME]
-h: this message
-p: save the file as a png.
-d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.
Besides the command screencap, there is another command screenshot, I don't know why screenshot was removed from Android 5.0, but it's avaiable below Android 4.4, you can check the source from here. I didn't make my comparison which is faster between these two commands, but you can give your try in your real environment and make the final decision.

Unable to run 'adb root' on a rooted Android phone [duplicate]

This question already has answers here:
adb shell su works but adb root does not
(11 answers)
Closed 5 years ago.
After rooting my device, I need to run adb root and then adb shell so I could then access my applications database. When trying to run adb root I keep getting "adbd cannot run as root in production builds". Why is this? The only other option is to use the Android emulator for testing, but we all know how terrible the emulator is (not really a viable development solution).
I finally found out how to do this! Basically you need to run adb shell first and then while you're in the shell run su, which will switch the shell to run as root!
$: adb shell
$: su
The one problem I still have is that sqlite3 is not installed so the command is not recognized.

Using ADB command know the name of application focussed using adb [duplicate]

This question already has answers here:
ADB - Android - Getting the name of the current activity
(13 answers)
Closed 4 years ago.
I am using the
adb shell input keyevent KEYCODE_DPAD_LEFT
to focus on an application, now i want to know the name of the application on which this has focussed using adb shell command.
NOTE: not exactly the name of application, it can focus on anything. SO i want to get the Text on which it focusses.
Ok. To do it, you need to use grep terminal application on your phone (the easiest way with rooted phone with busybox package). Let do the same steps as below:
C:\Users\Hasan>adb shell input keyevent KEYCODE_DPAD_LEFT
C:\Users\Hasan>adb shell
shell#android:/ $ su
su
root#android:/ # dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
mCurrentFocus=Window{42079c60 com.jrummy.liberty.toolboxpro/com.jrummy.apps.rom.toolbox.RomToolboxActivity paused=false}
mFocusedApp=AppWindowToken{4283d918 token=Token{426709a8 ActivityRecord{41e37c60 com.jrummy.liberty.toolboxpro/com.jrummy.apps.rom.toolbox.RomToolboxActivity}}}
root#android:/ #
Now you'll see which activity has focus :)
You can use:
adb shell uiautomator dump /dev/tty
You will get an XML describing the current screen, one of the many <node>-elements will have an attribute focused="true". It may also have a text-attribute and a lot more UI-informations.

adb shell auto-complete under Windows 7

Regarding this post: adb shell auto-complete under Windows 7?
The owner's answer is: "Solved this problem by recompiling adb under cygwin. :)"
Unfortunately I can't send comments asking him how did he recompiled the adb under cygwin.
So my question is: How could I recompile adb under cygwin to get auto-compete working in adb?
EDIT: I realized that actually cygwin is already auto-completing when I type inside android bash, but the text is not being showed. Weird, isn't? E.g:
# ls /data/tem
[TAB]
# ls/data/tem | <<<--- the cursor jumps to here
[ENTER]
It list all files and folders within /data/temp folder.
You can use ADB enhanced Putty
It support auto complete and coloring
you can download it from
ADB Putty
Just start it suing the following command-line:
adb-putty.exe -adb -P 5037 transport-usb
read more at ADB enhanced Putty (replacement for "adb shell" command)
Try PuTTY Tray. Its work for me!
connect to the phone via "adb connect ip:port"
run Putty Tray, select Adb and click "Open"
PS.
You can specify device ID in session settings.
I'm (fortunately) not a Windows user but I guess the problem is not in adb but in your shell that is not letting some keys (i.e. TAB) reach it.
Try this to see if TAB is received by the android shell:
adb shell
# printf '%d\n' "'$(dd bs=1 count=1 2>/dev/null)"
<type TAB+ENTER>
9
If you cannot see 9 (ascii TAB) then your problem is in the Windows shell and you could try cygwin bash to reproduce the test and see the results.
Are you mis-understanding the original post? I think that guy is saying he stopped using the Command Prompt and switched to cygwin.
You can make auto complete work in the Windows command prompt as well. Just run cmd /f instead of cmd. The other post has instructions on how to permanently enable autocomplete.
If you want to use cygwin then focus on trying to get autocomplete to work in cygwin. It's been years since I used cygwin, but I thought it was enabled by default. Maybe you need to turn off case sensitivity? How to deactivate uppercase check in cygwin folder autocompletion?
Regardless which shell you use it will only auto complete folder and file names.

Categories

Resources