Comprehensive Guide to Android Debug Bridge (ADB) Commands and Their Practical Uses
This article provides an extensive overview of Android Debug Bridge (ADB), detailing its architecture, core components, and a wide range of commands—including shell am, pm, appops, wm, settings, input, dumpsys, logcat, push/pull, screencap, and screenrecord—illustrated with examples and code snippets for effective mobile testing and automation.
ADB (Android Debug Bridge) is a three‑part client‑server‑daemon system that enables communication between a PC and Android devices or emulators, allowing installation, debugging, and control of apps.
ADB Components
The client runs on the PC and checks if the ADB server is active; if not, it starts the server on port 5037. The server manages connections to device‑side daemons, and the daemon runs on the Android device.
Common adb shell am Commands
Use adb shell am start to launch an activity, adb shell am startservice to start a service, adb shell am stopservice to stop a service, and adb shell am force-stop or adb shell am kill to terminate an app.
Package Manager (adb shell pm)
Commands such as adb shell pm list package, adb shell pm install, adb shell pm uninstall, and adb shell pm clear manage app installation, removal, and data clearing, with various flags (e.g., -r, -s, -f) to control behavior.
AppOps (adb shell appops)
Use adb shell appops get to view permission usage, adb shell appops set to modify permission state (allow, deny, ignore, default), and adb shell appops reset to restore original permissions.
Window Management (adb shell wm)
Commands like adb shell wm size, adb shell wm density, and adb shell wm overscan adjust screen resolution, density, and display area temporarily.
System Settings (adb shell settings)
Retrieve or modify system parameters with adb shell settings get/put/delete across the system, secure, and global namespaces.
Input Simulation (adb shell input)
Simulate text entry ( adb shell input text 'HelloADB'), key events ( adb shell input keyevent KEYCODE_MENU), taps, swipes, and other gestures to automate UI interactions.
Dumpsys (adb shell dumpsys)
Extract system diagnostics such as CPU usage ( adb shell dumpsys cpuinfo), battery status, package info, and activity stack ( adb shell dumpsys activity top) for performance analysis.
Logcat (adb logcat)
View runtime logs with filtering options; control output format using -v parameters (e.g., adb logcat -v brief) and filter by tag or PID.
File Transfer (adb push/pull)
Transfer files between host and device using adb push sourceFile /sdcard/ and adb pull /sdcard/file localFile, optionally renaming during transfer.
Screen Capture and Recording
Capture screenshots with adb shell screencap /sdcard/Test.png and record video with adb shell screenrecord /sdcard/Test.mp4, then retrieve the media via adb pull.
Server Control
Restart the ADB server using adb kill-server followed by adb start-server to apply configuration changes or recover from connection issues.
Mastering these ADB commands enables efficient Android testing, debugging, and automation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JD Tech
Official JD technology sharing platform. All the cutting‑edge JD tech, innovative insights, and open‑source solutions you’re looking for, all in one place.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
