Support free tutorials:
Using the Android Debug Bridge (adb) Tutorial
Lars Vogel
Version11.2
Copyright2009,2010,2011,2012,2013LarsVogel
28.10.2013
Revision History
Revision 0.1 - 11.2
04.07.2009 - 28.10.2013
bug fixing and enhancements
Using the adb tools with Android
ThistutorialdescribeshowtousetheadbtooltoaccessyourAndroiddeviceorAndroidvirtualdevice(AVD).
TableofContents
1. Android Debugging Bridge - adb
2. Shell access via adb
3. Copy files from and to your device
4. Uninstall an application via adb
5. Telnet your your Android device
6. Comand line tool dumpsys
6.1. adb dumpsys
6.2. Memory consumption overview with
dumpsys
6.3. Information about schedule tasks
7. Support free vogella tutorials
7.1. Thank you
7.2. Questions and Discussion
8. Links and Literature
8.1. Source Code
8.2. Android Resources
8.3. vogella Resources
Search Training Books Blog Shop Contact us
vogella.com Tutorials
1. Android Debugging Bridge - adb
YoucanaccessyourAndroiddeviceviatheadbcommandonthecommandline..AnAndroidvirtualdevicecanbe
freelyaccessed,anormalAndroidphoneneedstogetrooted,e.g.youneedtoremovetheprotectiontodo
everythingonthisdevice.
Theadbtoolsislocatedinthe[android-sdks]/platform-toolsdirectory.Youshouldaddthisdirectorytoyour
pathtohavedirectaccesstothiscommand.
TheadballowsyoutosendcommandstoyourAndroiddevice,pullandpushfilestoit,givesshellaccesstothe
Androiddeviceandallowsyoutoreadinformationfromyourdevice,forexamplethecurrentmemoryusage.The
followingchapterdescribetheusageofthecorrespondingcommands.
Ifyouhaveseveraldevicesrunningyoucanissuecommandstooneindividualdevice.
# 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
YoucangetshellaccesstoyourAndroiddeviceviathefollowingcommand.
adb shell
ThiswillconnectyoutoyourdeviceandgiveyouLinuxcommandlineaccesstotheunderlyingfilesystem,e.g.ls,
rm,,cd,mkdir,etc.Theapplicationdataisstoredinthedirectory"/data/data/package_of_your_app".
3. Copy files from and to your device
Youcancopyafilefromandtoyourdeviceviathefollowingcommands.
// 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
Youcanuninstallanandroidapplicationviatheshell.Switchthedata/appdirectory(cd/data/app)andsimply
deleteyourandroidapplication.
Youcanalsouninstallanappviaadbwiththepackagename.
adb uninstall <packagename>
5. Telnet your your Android device
Alternativelytoadbyoucanalsousetelnettoconnecttothedevice.Thisallowsyoutosimulatecertainthings,e.g.
incomingcall,changethenetworkconnectivity,setyourcurrentgeocodes,etc.Use"telnetlocalhost5554"to
connecttoyoursimulateddevice.Toexittheconsolesession,usethequitorexitcommand.
Forexampletochangethepowersettingsofyourphone,toreceiveansmsandtogetanincomingcallmakethe
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
FormoreinformationontheemulatorconsolepleaseseeEmulatorConsolemanual
6. Comand line tool dumpsys
6.1. adb dumpsys
Theadb dumpsyscommandallowsyoutoretaininformationabouttheAndroidsystemandtherunningapplications.
Togetcurrentlymemoryconsumptionofanapplicationyoucanusethefollowingcommand.
adb shell dumpsys meminfo <package.name>
6.2. Memory consumption overview with dumpsys
Theadb shell procranklistsyouallapplicationintheorderoftheirmemoryconsumption.Thiscommanddoesnot
workonrealdevice.Usetheadb shell dumpsys meminfoinstead.
6.3. Information about schedule tasks
Tofindwhichalarmsarescheduledforyourapplication,usetheadb shell dumpsys alarmcommandandlookfor
yourpackagename.Theoutputmightbesimilartothefollowing:
RTC #6: Alarm{434a1234 type 1 com.example}
type=1 whenElapsed=608198149 when=+12m13s122ms window=-1 repeatInterval=0 count=0
operation=PendingIntent{430cf612: PendingIntentRecord{*43bbf887* com.vogella startS
ervice}}
Thisshowstheinfothatthealarmisscheduledforapprox.12minutes.
Tofindouttheinformationaboutthependingintent,runtheadb shell dumpsys activity intentscommandand
lookfortheIDofthePendingIntentRecord(inthisexample43bbf887):
* PendingIntentRecord{43bbf887 com.vogella startService}
uid=10042 packageName=com.vogella type=startService flags=0x0
requestIntent=act=MY_ACTION cmp=com.vogella/.MyService (has extras)
7. Support free vogella tutorials
ThistutorialisOpenContentundertheCCBYNCSA3.0DElicense.Sourcecodeinthistutorialislicensedunder
theEclipsePublicLicensefordetails.Seefordetails.tab
Maintaininghighqualityfreeonlinetutorialsisalotofwork.Pleasesupportfreetutorialsbydonatingorbyreporting
typosandfactualerrors.
7.1. Thank you
Pleaseconsideracontributionifthisarticlehelpedyou.
7.2. Questions and Discussion
Ifyoufinderrorsinthistutorial,pleasenotifyme(seethetopofthepage).Pleasenotethatduetothehigh
volumeoffeedbackIreceive,Icannotanswerquestionstoyourimplementation.Ensureyouhavereadthe
vogellaFAQasIdon'trespondtoquestionsalreadyansweredthere.
8. Links and Literature
8.1. Source Code
SourceCodeofExamples
8.2. Android Resources
AndroidIntroductionTutorial
AndroidListViewandListActivity
AndroidSQliteDatabase
AndroidWidgets
AndroidLiveWallpaper
AndroidServices
AndroidLocationAPIandGoogleMaps
AndroidIntents
AndroidandNetworking
AndroidHomepage
AndroidDeveloperHomepage
AndroidIssues/Bugs
AndroidGoogleGroups
AndroidLiveFolder
8.3. vogella Resources
vogellaTrainingAndroidandEclipseTrainingfromthevogellateam
AndroidTutorialIntroductiontoAndroidProgramming
GWTTutorialPrograminJava,compiletoJavaScriptandHTML
EclipseRCPTutorialCreatenativeapplicationsinJava
JUnitTutorialTestyourapplication
GitTutorialPutallyourfilesinadistributedversioncontrolsystem