2017-12-24

adb-cheatsheet

ADB

[TOC]

四大组件 ABCS

Activity

1
2
3
4
5
# start activity
adb shell am start -n your.package.name/.YourActivityName
# with param
am start -a android.intent.action.VIEW -c android.intent.category.DEFAULT
-e ${paramName} ${value} -n your.package.name/.YourActivityName

Broadcast

1
2
3
4
5
6
7
8
9
# send a broadcast
adb shell am broadcast -a com.your.action

# send a broadcast with param
# --es -> string
# --ei -> int
# --ez -> boolean
# ...
adb shell am broadcast -a com.your.action --es ${name} ${content}

ContentProvider

1
2
3
4
5
6
7
8
9
adb shell content query --uri $uri 
adb shell content delete --uri $uri
adb shell content update --uri $uri --bind ${name}:${type}:${value}
adb shell content update --uri $uri \
--bind ${paramNameA}:${type}:${value} \
--bind ${paramNameB}:${type}:${value}

# <TYPE>
# b - boolean, s - string, i - integer, l - long, f - float, d - double

Service

1
2
3
4
5
6
7
8
9
10
 adb shell am startservice -a com.android.action.WHATEVER -e ${paramName} ${value}  your.package.name/.YourServiceName

adb shell dumpsys audio
adb shell dumpsys power
adb shell dumpsys iphonesubinfo
adb shell dumpsys meminfo
adb shell dumpsys package ${package}
adb shell dumpsys activity service ${package}
adb shell dumpsys activity ${package}/.xxxx (service name in manifest)
...

Tips: 实现 service 时重写 dump 方法就可以用 dumpsys 打印想要的信息


Cheatsheet

adb shell pm

1
2
3
4
# show all package
adb shell pm list package
# or
adb shell cmd package list package

adb shell input

1
2
3
adb shell input text "content"
adb shell input keyevent 4 # send key back event
# more https://developer.android.com/reference/android/view/KeyEvent.html#ACTION_DOWN

getCurrentActivity

1
adb shell dumpsys window windows | grep 'mCurrentFocus'

kill specify package

1
adb shell kill $(adb shell ps |grep "package1\|package2\|package3" |awk '{printf "%s ",$2}')