Understanding Android Debug Bridge (ADB) Commands

 
L
e
c
t
u
r
e
 
8
:
 
A
D
B
 
Topics: Basic ADB Commands
 
W
h
a
t
 
i
s
 
A
D
B
?
 
Android Debug Bridge (ADB) is a 
command line
utility 
to communicate with your Android device.
 
 
Uses:
Listing connected devices.
Installing and debugging apps.
Copy files to and from the phone.
Take screenshots, record screens, etc.
<android_sdk_path>
/platform-tools/adb.exe
 
A
D
B
 
C
l
i
e
n
t
-
S
e
r
v
e
r
 
A
r
c
h
i
t
e
c
t
u
r
e
 
Three entities are involved: a client, a server, a
daemon (adbd).
 
Server
Daemon
 
Port: 5037
 
Port: 555X
Client
 
Background
process
 
Background
process
 
Invoked From
Terminal
C
o
n
n
e
c
t
i
n
g
 
o
v
e
r
 
U
S
B
Remember the first thing we did with the phone?
Settings>About Phone>
Build number
Settings>Developer options>
USB Debugging
 
Why?
T
e
s
t
i
n
g
 
t
h
e
 
A
D
B
Use a shell to invoke your first command:
USB
adb devices -l
List of devices attached
071b799a344bdc6b       device product:hammerhead model:Nexus_5 device:hammerhead
W
h
e
n
 
t
h
i
n
g
s
 
g
o
 
w
r
o
n
g
 
Use a shell to kill and start the server:
USB
adb kill-server
adb start-server
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
 
A
D
B
 
o
v
e
r
 
W
i
F
i
 
Set TCP port (over USB) and connect (over WiFi)
adb tcpip 5555
 
(USB must be connected)
adb connect [Phone’s IP Addr]
 
(USB must be disconnected)
 
To get your phone’s IP address: 
adb shell ifconfig
 
A
D
B
 
C
o
m
m
a
n
d
s
 
Now, you can communicate with the phone.
adb shell screencap /sdcard/s.png
adb pull /sdcard/s.png <local>
 
or
 
U
s
e
f
u
l
 
A
D
B
 
C
o
m
m
a
n
d
s
 
Global Options:
adb –d <command>
adb –e <command>
adb –s <serial number> <command>
 
071b799a344bdc6b
 
071b799a344bdxyz
U
s
e
f
u
l
 
A
D
B
 
C
o
m
m
a
n
d
s
General adb Commands:
adb devices -l
adb help
adb version
Network/File/Install adb Commands:
adb connect 
ip[:port]
adb disconnect 
ip[:port]
adb pull [-a] 
remote local
adb push 
local remote
adb install 
package
adb uninstall 
package
U
s
e
f
u
l
 
A
D
B
 
C
o
m
m
a
n
d
s
backup/debug/scripting adb Commands:
adb backup 
[-f file] 
[-apk][-obb][-shared][-all][-system]
adb restore 
file
adb logcat 
[option]
adb root
adb unroot
adb usb
adb tcpip 
port_555X
adb start-server
adb kill-server
adb reconnect
Activity Manager (am commands)
I
s
s
u
i
n
g
 
s
h
e
l
l
 
C
o
m
m
a
n
d
s
Generic format (two ways):
adb shell 
<command>           
(execute on device shell)
adb shell                      
(get a device shell)
am start 
[option] intent 
(e.g., -a android.media.action.VIDEO_CAMERA)
am startservice 
[option] intent
am broadcast 
[option] intent
am force-stop 
package
am kill 
[option] package
am kill-all
Screen capture
I
s
s
u
i
n
g
 
s
h
e
l
l
 
C
o
m
m
a
n
d
s
Package Manager (pm commands)
pm list packages 
[options] filter
pm list permissions 
[options] filter
pm list features
pm list libraries
pm list users
pm install 
[options] path
pm uninstall 
[options] package
pm grant 
package permission
pm revoke 
package permission
screencap 
filename
screenrecord 
[option] filename
I
s
s
u
i
n
g
 
s
h
e
l
l
 
C
o
m
m
a
n
d
s
Many more Unix commands!
ls
cd directory
chmod
df
mkdir
rm 
file
rmdir 
dir
 
ifconfig
iftop
netstat
ping 
host
echo 
text
date
time
reboot
ps
top
S
h
e
l
l
 
c
o
m
m
a
n
d
s
 
f
r
o
m
 
A
n
d
r
o
i
d
 
A
P
P
s
Use 
‘Runtime’ 
and 
‘Process’ 
classes to issue shell
commands from an Android app:
try 
{
    Process p = Runtime.
getRuntime
().exec(
"ps"
);
    InputStreamReader isr = 
new 
 
 
InputStreamReader(p.getInputStream());
    BufferedReader br = 
new 
BufferedReader(isr);
    String str =
""
;
    
while
((str = br.readLine()) != 
null
){
        Log.
v
(
"Tag"
, str);
    }
} 
catch 
(IOException e) {
    e.printStackTrace();
}
 
R
e
f
e
r
e
n
c
e
s
 
https://developer.android.com/studio/command-line/adb.html
Slide Note
Embed
Share

Android Debug Bridge (ADB) is a powerful command-line utility used to communicate with Android devices. It allows you to perform various tasks such as listing connected devices, installing apps, transferring files, taking screenshots, and more. Learn about ADB client-server architecture, connecting over USB, testing ADB commands, troubleshooting issues, using ADB over WiFi, and common ADB commands for effective communication with your Android device.


Uploaded on Jul 17, 2024 | 3 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Lecture 8: ADB Lecture 8: ADB Topics: Basic ADB Commands

  2. What is ADB? What is ADB? Android Debug Bridge (ADB) is a command line utility to communicate with your Android device. <android_sdk_path>/platform-tools/adb.exe Uses: Listing connected devices. Installing and debugging apps. Copy files to and from the phone. Take screenshots, record screens, etc.

  3. ADB Client ADB Client- -Server Architecture Server Architecture Three entities are involved: a client, a server, a daemon (adbd). Related image Port: 5037 Port: 555X Client Server Daemon Background process Invoked From Terminal Background process

  4. Connecting over USB Connecting over USB Remember the first thing we did with the phone? Settings>About Phone> Build number Settings>Developer options> USB Debugging Why?

  5. Testing the ADB Testing the ADB Use a shell to invoke your first command: adb devices -l List of devices attached 071b799a344bdc6b device product:hammerhead model:Nexus_5 device:hammerhead Related image USB

  6. When things go wrong When things go wrong Use a shell to kill and start the server: adb kill-server adb start-server * daemon not running. starting it now at tcp:5037 * * daemon started successfully * Related image USB

  7. ADB over ADB over WiFi Set TCP port (over USB) and connect (over WiFi) WiFi adb tcpip 5555 (USB must be connected) adb connect [Phone s IP Addr] (USB must be disconnected) Related image To get your phone s IP address: adb shell ifconfig

  8. ADB Commands ADB Commands Now, you can communicate with the phone. adb shell screencap /sdcard/s.png adb pull /sdcard/s.png <local> Related image or

  9. Useful ADB Commands Useful ADB Commands Global Options: adb d <command> adb e <command> adb s <serial number> <command> Related image 071b799a344bdc6b 071b799a344bdxyz

  10. Useful ADB Commands Useful ADB Commands General adb Commands: adb devices -l adb help adb version Network/File/Install adb Commands: adb connect ip[:port] adb disconnect ip[:port] adb pull [-a] remote local adb push local remote adb install package adb uninstall package

  11. Useful ADB Commands Useful ADB Commands backup/debug/scripting adb Commands: adb backup [-f file] [-apk][-obb][-shared][-all][-system] adb restore file adb logcat [option] adb root adb unroot adb usb adb tcpip port_555X adb start-server adb kill-server adb reconnect

  12. Issuing shell Commands Issuing shell Commands Generic format (two ways): adb shell <command> (execute on device shell) adb shell (get a device shell) Activity Manager (am commands) am start [option] intent (e.g., -a android.media.action.VIDEO_CAMERA) am startservice [option] intent am broadcast [option] intent am force-stop package am kill [option] package am kill-all

  13. Issuing shell Commands Issuing shell Commands Package Manager (pm commands) pm list packages [options] filter pm list permissions [options] filter pm list features pm list libraries pm list users pm install [options] path pm uninstall [options] package pm grant package permission pm revoke package permission Screen capture screencap filename screenrecord [option] filename

  14. Issuing shell Commands Issuing shell Commands Many more Unix commands! echo text date time reboot ifconfig iftop netstat ping host ls cd directory chmod df mkdir rm file rmdir dir ps top

  15. Shell commands from Android APPs Shell commands from Android APPs Use Runtime and Process classes to issue shell commands from an Android app: try { Process p = Runtime.getRuntime().exec("ps"); InputStreamReader isr = new InputStreamReader(p.getInputStream()); BufferedReader br = new BufferedReader(isr); String str =""; while((str = br.readLine()) != null){ Log.v("Tag", str); } } catch (IOException e) { e.printStackTrace(); }

  16. References References https://developer.android.com/studio/command-line/adb.html

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#