






如上-e代表push到模擬器中,/mnt/sdcard/代表SD卡
adb logcat wait-for-device等待設備一連接就開始抓LOG



從電腦上遠程控制手機

打開設備上的monkey端口

將PC的1080端口印射到手機上的1080端口上,這樣所有通過電腦1080端口的信息都會發住手機

遠程連接電腦上的端口,比如發送一些按鍵信息,這樣就能傳遞到手機上了
adb 無線連接與文件同步
adb connect + IP ,可以鏈接某個設備。
這個命令在調試真機的時候,使用頻繁。 但注意: 1.要鏈接的IP ,必須和自己的PC的網絡在同一個局域網內,adb 不能跨局域網鏈接設備 2.如果通過usb鏈接android設備,通過adb devices 可以看見設備列表,但是使用不了,可以參考下面的命令 adb tcpip 5555 adb connect 192.168.0.101:5555
adb shell getprop dhcp.wlan0.ipaddress獲取設備的IP地址
adb get-serialno 獲取設備的ID和序列號serialNumber
說明:
序列號[serialNumber]——由adb創建的一個字符串,這個字符串通過自己的控制端口<type>-<consolePort>
唯一地識別一個模擬器/設備實例。一個序列號的例子: emulator-5554
adb get-state 查看模擬器/設施的當前狀態.
adb forward <local> <remote>發布端口,可以設置任意的端口號,
adb forward tcp:6100 tcp:7100 // PC上所有6100端口通信數據將被重定向到手機端7100端口server上
adb wait-for-device 在模擬器/設備連接之前把命令轉載在adb的命令器中
adb jdwp 查看指定的設施的可用的JDWP信息.
adb shell input text <string> 向設備輸入文本(光標所在的文本框)
adb shell input keyevent <event_code> 向設備發送按鍵事件
input tap , 對屏幕發送一個觸摸事件
adb shell input tap 500 500
input swipe , 滑動事件
adb shell input swipe 900 500 100 500
在編輯短信時,往文本框輸入文本:adb shell input text "hello"
向手機發送鍵值回Home:adb shell input keyevent 3
event_code 參考view/KeyEvent.java中的 KEYCODE_*
public static final int KEYCODE_SOFT_LEFT = 1;
public static final int KEYCODE_SOFT_RIGHT = 2;
public static final int KEYCODE_HOME = 3;
public static final int KEYCODE_BACK = 4;
public static final int KEYCODE_CALL = 5;
public static final int KEYCODE_ENDCALL = 6;
adb shell procrank 查詢各進程內存使用情況
adb shell service list 查看services信息
adb shell cat /proc/meminfo 查看當前的內存情況
adb shell cat /proc/cpuinfo 查看CPU信息(硬件)
adb shell cat /proc/iomem 查看IO內存分區
adb shell getprop 列出系統所有屬性
adb shell getprop | findstr "gsm" 列出包含gsm的屬性
adb shell setprop <key> <value> 修改系統屬性
adb shell sqlite3 可以執行sql語句查看數據庫信息, 具體使用情況待調查
adb shell dmesg 查詢內核緩沖區信息
adb shell dumpstate 各類信息,比如進程信息,內存信息,進程是否異常,kernnel的log等
adb shell dumpcrash
adb shell dumpsys 查詢所有service的狀態
adb reboot-bootloader 重啟到bootloader
adb reboot recovery 重啟到recovery
adb push flash_image.zip /system/bin/flash_image 增加flash_image文件到手機上
android list targets 顯示系統中全部Android平台
android list avd 顯示系統中全部AVD(模擬器):
adb shell screencap -p /sdcard/penghong.png(參數-p為保存為png格式)
adb shell screenrecord /sdcard/demo.mp4 錄制視頻
adb shell pm dump com.tencent.mobileqq 列出指定應用的 dump 信息
adb shell pm install , 安裝應用存放於 Android 設備上(安裝存放於電腦上的用adb install)
am
又是一個龐大的命令。。。
am 源碼 Am.java
am start , 啟動一個 Activity,已啟動系統相機應用為例
啟動相機
[xuxu:~]$ adb shell am start -n com.android.camera/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }
先停止目標應用,再啟動
[xuxu:~]$ adb shell am start -S com.android.camera/.Camera
Stopping: com.android.camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
等待應用完成啟動
[xuxu:~]$ adb shell am start -W com.android.camera/.Camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
Status: ok
Activity: com.android.camera/.Camera
ThisTime: 500
TotalTime: 500
Complete
啟動默認瀏覽器打開一個網頁
[xuxu:~]$ adb shell am start -a android.intent.action.VIEW -d http://testerhome.com
Starting: Intent { act=android.intent.action.VIEW dat=http://testerhome.com }
啟動撥號器撥打 10086
[xuxu:~]$ adb shell am start -a android.intent.action.CALL -d tel:10086
Starting: Intent { act=android.intent.action.CALL dat=tel:xxxxx }
am instrument , 啟動一個 instrumentation , 單元測試或者 Robotium 會用到
am monitor , 監控 crash 與 ANR
[xuxu:~]$ adb shell am monitor
Monitoring activity manager... available commands:
(q)uit: finish monitoring
** Activity starting: com.android.camera
am force-stop , 后跟包名,結束應用
am startservice , 啟動一個服務
am broadcast , 發送一個廣播
adb shell uiautomator dump 獲取當前界面的控件信息
adb shell ime list -s 列出設備上的輸入法
adb shell wm size 獲取手機分辨率
adb shell settings https://testerhome.com/topics/1993
adb shell dumpsys dropbox [--print|--file] [YYYY-mm-dd] [HH:MM:SS] [tag] app發生crash,未及時在logcat中抓取到有效log時,可通過該腳本獲取到log,app報錯時間關鍵字“data_app_crash”
adb shell dumpsys package com.tencent.mm|findstr android.permission獲取應用的權限
8.獲取通知信息:
adb shell dumpsys notification
7.adb shell dumpsys wifi
可以獲取到當前連接的wifi名、搜索到的wifi列表、wifi強度等
獲取電源管理信息:
adb shell dumpsys power 可以獲取到是否處於鎖屏狀態:mWakefulness=Asleep或者mScreenOn=false 亮度值:mScreenBrightness=255 屏幕休眠時間:Screen off timeout: 60000 ms 屏幕分辨率:mDisplayWidth=1440,mDisplayHeight=2560 等
獲取電話信息:
adb shell dumpsys telephony.registry 可以獲取到電話狀態,例如 mCallState值為0,表示待機狀態、1表示來電未接聽狀態、2表示電話占線狀態 mCallForwarding=false #是否啟用呼叫轉移 mDataConnectionState=2 #0:無數據連接 1:正在創建數據連接 2:已連接 mDataConnectionPossible=true #是否有數據連接 mDataConnectionApn= #APN名稱 等
adb shell dumpsys window displays |findstr init 獲取手機分辨率
使用命令adb shell dumpsys alarm 來檢測app的alarm喚醒次數
adb 獲取WIFI密碼:adb shell后,然后cat /data/misc/wifi/*.conf命令
手機不識卡的解決辦法:adb shell setprop persist.radio.multisim.config dsds
adb shell getprop dalvik.vm.heapgrowthlimit單個應用程序最大內存限制
adb shell dumpsys battery set usb 0 屏蔽USB充電
cat /proc/stat命令 查看CPU時間片
查看 TP相關的信息
adb shell getevent 查看input設備屬於哪一個event
adb shell getevent dev/input/event1
與input event 對應的信息 root@android:/ # cat/proc/bus/input/devices
查看TP上報的速率: getevent -r /dev/input/event1
查看TP上報的鍵值:getevent -l/dev/input/event1
/system/build.prop中 JAVA虛擬機內存使用上限,還可以adb shell getprop查看
adb shell getprop|findstr dalvik.vm.heapgrowthlimit
adb logcat -c 清空手機中的log
單個應用程序最大內存限制,超過這個值會產生OOM
adb shell cat /system/build.prop>phone.info
ro.build.version.release android版本號
ro.product.model 機型
ro.product.brand分支
adb shell pm clear com.android.contacts清除數據
adb nodaemon server查看adb的端口號
