2.3 KiB
2.3 KiB
am
start
用am start來打開一個activity,例:
adb shell am start -S com.logitech.sentineliq/.MainActivity --es cameraId 0
其中-S是指先停止app再打開app。還有其他的命令如下:
-D: enable debugging
-W: wait for launch to complete
--start-profiler <FILE>: start profiler and send results to <FILE>
-P <FILE>: like above, but profiling stops when app goes idle
-R: repeat the activity launch <COUNT> times. Prior to each repeat,
the top activity will be finished.
-S: force stop the target app before starting the activity
--opengl-trace: enable tracing of OpenGL functions
參考
pm
list packages
列出所有安裝的apk
adb shell pm list packages
只列出 user 自己安裝的 apk:
adb shell "pm list packages -3"
Forward
ADB forward用來把PC端收到的TCP轉到Android去,這樣就可以透過USB ADB達到網路的功能。 例:
adb forward tcp:6100 tcp:7100
上述等於:
PC Android
http://127.0.0.1:6100 APP(port: 8080)
| |
| |
V----------> ADB(USB)----------->
Android端所回應的HTTP封包也會經由原路回來,但是如果Android端要發一個request的話,PC端就收不到了,必須經由ADB#Reverse才行。
參考
Reverse
ADB reverse用來監聽Android端收到的request,假設今天在Android APP上寫一個http://127.0.0.1:8080/say/message,並希望PC端可以收到的話,就可以用reverse來操作,例:
adb reverse tcp:8081 tcp:8080
也就是說Android那邊發過來的封包會送交給PC這邊的port 8081。因此,PC端還需要寫一個Server來監聽8081才行。
參考
Logcat
- Enlarge logcat buffer to 16M:
adb logcat -G 16M
Get foreground activity
#android #foreground #activity
adb shell "dumpsys activity activities | grep ResumedActivity"