ADB commands for Android

ADB Stands for Android Debug Bridge, ADB is a command line tool which you can use to debug or communicate with any android device.

In order to run ADB from your machine, first you must install android SDK in your computer. ADB is the command line tool which comes in android SDK.

In order to run ADB from your machine, we need to have latest adb executable along with the corresponding device drivers. ADB is the command line tool which is part of android SDK. You can download complete sdk or adb executable alone, we can download.

Download from: http://developer.android.com/sdk/index.html

Now enable USB debugging in the device settings, under Developer options. After Installing SDK, to provide ADB Commands through command line you need to make “android sdk tools or adb executable” path available to systems environment variable to run from anywhere in the system environment. Otherwise, you need to run the adb commands only from the place, where the adb executable is present.

Let’s see ADB Commands.

ADB Command to view connected device(s)

This command prints a list of all attached emulator/device instances.

adb devices

If multiple devices are attached, use adb -s DEVICE_ID to target a specific device.

ADB Command to push and pull files

adb push <Source> <Destination>

This command sends files to your phone from local PC.

Example: adb push c:/example.apk /sdcard/

adb pull <Source> <Destination>

This command receives files from your phone to local PC.

Example: adb pull /system/app/example.apk c:/

ADB Command to Install and Uninstall an application

Install:

adb install -r APK_PATH

This command installs a given application to your device. Optional ‘-r’ argument reinstalls and keeps any data if the application is already installed on the device.

Ex: adb install -r c:/application.apk

Uninstall:

adb uninstall <PACKAGE_NAME>

This command uninstalls the given package from the device.

Ex: adb uninstall com.electrofriends.example

To start adb with root permissions:

adb root

ADB command to remount the device:

adb remount

ADB Command to enter into shell

adb shell

ADB Command to reboot the device

adb reboot

ADB Command to reboot the phone into bootloader

adb reboot bootloader

ADB Command to wipe data/factory reset

Suppose if you have forgotten the device password or for any reason if you want to factory reset your android device, here are the simple 3 steps to do the same.

1. First reboot your device in fastboot or bootloader mode:

adb reboot bootloader

2. Next erase all data

fastboot –w

3. Restart your device.

ADB Command Remount your device

adb remount

ADB Command to take device log

Below command will display the device logs on your command prompt.

adb logcat

Command to save device logs to a file

adb logcat > log

If you feel you are getting lots of unwanted logs, then filter by tagname

adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2

You can also filter logs by log priority.

adb logcat “*:PRIORITY”

# example

adb logcat “*:W”

Here are the priority levels of logs:

V – Verbose (lowest priority)
D – Debug
I – Info
W – Warning
E – Error
F – Fatal
S – Silent (highest priority, on which nothing is ever printed)

Filter using grep

Alternatively the output of logcat can be piped to grep on a system that supports it.

adb logcat | grep “ERROR”
adb logcat | grep “ERROR\|Exception”

ADB Command to clear the device log

This command will clear the device log buffer.

adb logcat -c

ADB Command to create and delete users

First you need to enable the multiuser support on your Android device. Then only the user menu will be visible in Android settings.

adb shell setprop fw.max_users 8

Now run bellow command to create new android device user

adb shell pm create-user Test_User

Below command is used delete the user based on user ID. There is no direct method is available to delete user based on user name.

pm remove-user User_ID

ADB Command to Start an activity

Use below command to start any activity

adb shell am start PACKAGE_NAME/ACTIVITY_NAME

Example:

ADB Command to start and stop settings app.

adb shell am start -n com.android.settings/.Settings
adb shell am force-stop com.android.settings

ADB Command to open device applications directly. 

adb shell am start -a android.intent.action.MAIN -n com.android.settings/.applications.ManageApplications

ABD Command to start and stop camera

adb shell am start -n com.android.camera2/com.android.camera.CameraLauncher
adb shell am force-stop com.android.camera2

ADB Command to launch camera in image capture mode and take picture

adb shell am start -a android.media.action.IMAGE_CAPTURE
adb shell input keyevent 27

ADB Command to launch camera in video capture mode and take video

adb shell am start -a android.media.action.VIDEO_CAPTURE
adb shell  input keyevent 27

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in