ADB advanced application, adb

Source: Internet
Author: User

ADB advanced application, adb
ADB advanced application 1. Use wireless to view adb shell> adb tcpip 5555
Connection:> adb connect IP: 5555
See "debugging notes"
2. Analog buttons> adb shell input keyevent "value"
Key | Constant ValueBack 4 Power 26 Menu 82 Home 3 Search 84
Direction key: Upper 19 lower 20 left 21 right 22 OK (similar to click): 23
3. view the system drive letter> adb shell df under adb shell
4. mount the system under adb shell> busybox mount-o remount, rw/system

5. Remove a USB device under the adb shell> vdc unshare/mnt/sdcard ums

6. view the kernel information under the adb shell> cat/proc/kmsg &
7. view the build configuration value (using heap as an example)> adb shell getprop | grep heap
8. Simulate buttons and mouse through sendevent
Use input directly:> adb shell input keyevent 3> adb shell input tap 250 250> adb shell input swipe 250 250 300

9. view the fps enabled system attribute displayed on the screen: debug. sf. fps = 1
Then logcat-s SurfaceFlinger-v time
(Check the number of times SurfaceFlinger prints out)


10. view the current running program Stack
> Dumpsys window windows | busybox grep "Window #"

11. view the Running frequency of the current device DDR> cat/proc/clocks | busybox grep "ddr"
12: ADB logcat filtering adb logcat-s TAG_NAME
Adb logcat-s TAG_NAME_1 TAG_NAME_2adb logcat "*: PRIORITY" adb logcat-s TAG_NAME: PRIORITY
Adb logcat-s TAG_NAME_1: PRIORITY_1 TAG_NAME_2: PRIORITY
PRIORITY is divided into the following types:

V-Verbose
D-Debug
I-Info
W-Warning
E-Error
F-Fatal
S-Silent
Example:> adb logcat *: E view exception information> adb logcat-s "TAG" filter TAG
13: Check whether the device has su permissions (4.2 and earlier versions)

> Adb shell
> Ps
# List System Processes
# Select a common program starting with u
> Su u0_a8
# Switch to u0_a8 # Change number>
> Su
# If it can be executed,> # indicates that you have the su permission. If a permission error is prompted, you do not have the su permission.


14. view application reference adb. view all Android Application references.> adb shell> ps (view PID)> cd/proc/PID/fd> busybox ls-l also copies the File> cat xxx>/sdcard/xxx
15th: Get running memory/CPU information> adb shell> cat/proc/meminfo> cat/proc/cpuinfo
Sixteen: capture Logcat information and kmsg information # cat proc/kmsg>/data/kmsg.txt &
# Logcat-v time>/data/logcat.txt &

17: View device information of Android (mobile phone, tablet, Development Board, etc.)

> Adb shell dumpsys package> package. xml

(This command can display the library and feature available for the mobile phone (tablet)




18. Output all installed applications> adb shell pm list packages-f




19. view the pre-installed apk


> Adb shell pm list packages-3
20: Clear the logcat buffer (Use this command to clear outdated logs that have already appeared)
> Adb logcat-c
21. adb command: capture screen images and save them to your computer
$ adb shell screencap -p | sed 's/\r$//' > screen.png

Execute adb shell to convert \ n to \ r \ n. Therefore, use sed to delete redundant \ r

If the command is used directly, you can use the alias package volume to install it.
$ alias and-screencap="adb shell screencap -p | sed 's/\r$//'"$ and-screencap > screen.png 

In the future, you can easily use and-screencap> to directly save it to your computer.




Other basic but common adb commands1. View All connected devices

Adb devices

If multiple devices are connected to your computer, you can use adb-s DEVICE_ID to specify which device to use.
2. Mount the system partition (of course, device support is required) adb remount
3. install and uninstall the application adb install <apk file path>
Adb install-r <apk file path> install the apk file using the install command. The-r parameter can reinstall an application and retain application data.

# Example
Adb install-r ~ /Chrome.apk

Uninstall an application:
Adb uninstall <software Name> adb uninstall-k <software Name> If the-k parameter is added, the configuration and cache files are retained for the uninstalled software.
# Example
Adb uninstall com. android. chrome
4. start an Activityadb shell am start package name/. Class Name
Adb shell am start package name/class full name
5. log on to the device shell

Adb shell -- this command will log on to the shell of the device.
Adb shell <command> is followed by the <command> command to directly run the device command, equivalent to executing a remote command


6. Send files to the device from the computer

-- Use the push command to copy files or folders on the local computer to the device (mobile phone)

Adb remount # remount '/system' partition as read-write

Adb push <local path> <remote path>


7. download files from your device to your computer

-- Use the pull command to copy files or folders on the device (mobile phone) to the local computer.

Adb pull <remote path> <local path>


8. display help information (including command usage and meaning)

Adb help




Reference: http://www.growingwiththeweb.com/2014/01/handy-adb-commands-for-android.htmlhttp://blog.csdn.net/wirelessqa/article/details/29187339http://blog.csdn.net/centralperk/article/details/7644725
Other references:
1. Analog function key Command Format: adb shell sendevent [device] [type] [code] [value]

For example, adb shell sendevent/dev/input/event0 1 229 1 means to press the menu key

Adb shell sendevent/dev/input/event0 1 229 0 means to press and release the menu key

Note: The preceding commands must be used in combination.

The command is as follows:

Key Name CODE

MENU 229

Back HOME 102

BACK (back button) 158

Calls (CALL button) 231

END (end call button) 107


2. Send a mouse event (Touch ):

Command Format: adb shell sendevent [device] [type] [code] [value]


Case 1: touch on a coordinate point

For example, if the x coordinate of the screen is 40 and the y coordinate is 210, run the following command:

Adb shell sendevent/dev/input/event0 3 0 40

Adb shell sendevent/dev/input/event0 3 1 210

Adb shell sendevent/dev/input/event0 1 1 330 1 // touch

Adb shell sendevent/dev/input/event0 0 0 0 // it must have

Adb shell sendevent/dev/input/event0 1 330 0 // untouch

Adb shell sendevent/dev/input/event0 0 0 0 // it must have

Note: The above six groups of commands must be used together.


Scenario 2: simulate a sliding track (download and test with aPaint software)

The following example shows a horizontal line starting with (100,200) and ending with (108,200) on aPaint.

Adb shell sendevent/dev/input/event0 3 0 100 // start from point (100,200)

Adb shell sendevent/dev/input/event0 3 1 200

Adb shell sendevent/dev/input/event0 1 1 330 1 // touch

Adb shell sendevent/dev/input/event0 0 0 0

Adb shell sendevent/dev/input/event0 3 0 0 101 // step to point (101,200)

Adb shell sendevent/dev/input/event0 0 0 0

........................ // Must list each step, here just skip

Adb shell sendevent/dev/input/event0 3 0 0 108 // end point (108,200)

Adb shell sendevent/dev/input/event0 0 0 0

Adb shell sendevent/dev/input/event0 1 330 0 // untouch

Adb shell sendevent/dev/input/event0 0 0 0

Debugging considerations

When debugging applications that use USB peripherals and host features, you are likely to connect your USB hardware to your Android device, this will prevent you from establishing an adb connection to the Android device through USB. You can still access adb through the network. Connect to adb through network:

  1. Connect the Android device to your computer through USB.
  2. Enter adb tcpip 5555 in the command line from the platform-tools directory of the SDK
  3. Enter: adb connect <device IP address>: 5555. Now you will be connected to the Android device and can issue general adb commands like adb logcat.
  4. To set your device to listen to USB, enter adb usb.



How to execute the adb command in an android Application

The ADB interface is mainly used to allow computers and other devices to control the Android system. Therefore, it is called "Intermediate bridge ";
It is not used by Android, but can be directly executed as SHELL, which has nothing to do with ADB.
Therefore, Android JAVA does not necessarily have encapsulated ADB classes. There are ADB service programs on the computer, port 5037,
It is an intermediate program that communicates with Daemon on the Android system.
If you want to execute the adb command on your mobile phone, you should directly follow the daemon process
(Daemon) communication. The methods that Baidu can find are not satisfactory.

The landlord uses exec to execute the CMD command. This is no longer an ADB interface. This is the SHELL of the system !!!

I do not know the effect of directly sending commands using socket/tcp. The address is 127.0.0.1, and the port of the android daemon process is used.
5555 is the start of an odd number.
... . Baidu can find the ADB dialog protocol. We recommend you try it.

The upstairs actually requires SHELL, not ADB. I found an article, but I have not tried it,
Do you need ROOT? I don't know. Attach it. Please try again.
If you are satisfied, you can adopt it!



How to run the adb command in the Application

Refer to/** clear cache */public static void cleanCache (String appPackageName) {Process process = null; DataOutputStream OS = null; String command = ""; try {process = runtime.getruntime(cmd.exe c ("su"); OS = new DataOutputStream (process. getOutputStream (); command = "rm-r/data/" + appPackageName + "/cache \ n"; OS. writeBytes (command); OS. flush (); OS. close (); process. waitFor (); process. destroy ();} catch (IOException e) {e. printStackTrace ();} catch (InterruptedException e) {e. printStackTrace ();}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.