Tutorial details

Using the Android Debug Bridge (adb) - Tutorial | App Code for Sale | Preview

Using the Android Debug Bridge (adb) - Tutorial | Android Tutorial

How to use the adb tool to access your Android device or Android virtual device (AVD)

Overview PAGE TOP

Lars Vogel

Version 11.1

Copyright © 2009, 2010, 2011, 2012, 2013 Lars Vogel

02.05.2013

table135.JPG

Using the adb tools with Android

This tutorial describes how to use the adb tool to access your Android device or Android virtual device (AVD).

1. Android Debugging Bridge - adb PAGE TOP

You can access your Android device via the adb command on the command line. . An Android virtual device can be freely accessed, a normal Android phone needs to get rooted, e.g. you need to remove the protection to do everything on this device.

The adb tools is located in the [android-sdks]/platform-tools directory. You should add this directory to your path to have direct access to this command.

The adb allows you to send commands to your Android device, pull and push files to it, gives shell access to the Android device and allows you to read information from your device, for example the current memory usage. The following chapter describe the usage of the corresponding commands.

If you have several devices running you can issue commands to one individual device.

# Lists all devices
adb devices
#Result
List of devices attached
emulator-5554 attached
emulator-5555 attached
# Issue a command to a specific device
adb -s emulator-5554 shell

2. Shell access via adb PAGE TOP

You can get shell access to your Android device via the following command.

adb shell 

This will connect you to your device and give you Linux command line access to the underlying file system, e.g. ls, rm, , cd, mkdir, etc. The application data is stored in the directory "/data/data/packageofyour_app".

You can copy a file from and to your device via the following commands.

// Assume the gesture file exists on your Android device
adb pull /sdcard/gestures ~/test
// Now copy it back
adb push ~/test/gesture /sdcard/gestures2

4. Uninstall an application via adb PAGE TOP

You can uninstall an android application via the shell. Switch the data/app directory (cd /data/app) and simply delete your android application.

You can also uninstall an app via adb with the package name.

adb uninstall <packagename> 

5. adb dumpsys PAGE TOP

The adb dumpsys command allows you to retain information about the Android system and the running applications.

To get currently memory consumption of an application you can use the following command.

adb shell dumpsys meminfo <package.name> 

6. Emulator Console via telnet PAGE TOP

Alternatively to adb you can also use telnet to connect to the device. This allows you to simulate certain things, e.g. incoming call, change the network connectivity, set your current geocodes, etc. Use "telnet localhost 5554" to connect to your simulated device. To exit the console session, use the quit or exit command.

For example to change the power settings of your phone, to receive an sms and to get an incoming call make the following.

# connects to device
telnet localhost 5554
# set the power level
power status full
power status charging
# make a call to the device
gsm call 012041293123
# send a sms to the device
sms send 12345 Will be home soon
# set the geo location
geo fix 48 51

For more information on the emulator console please see Emulator Console manual

Reference PAGE TOP

http://www.vogella.com/articles/AndroidCommandLine/article.html

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.