無線連接
查看應用
安裝 APK
清除應用數據與緩存
Activity
發送廣播
模擬按鍵(文本)輸入
查看設備信息
無線連接
通過 IP 地址連接設備。
adb connect <device-ip-address>
斷開無線連接
adb disconnect <device-ip-address>
查看應用
所有應用:
adb shell pm list packages
系統應用:
adb shell pm list packages -s
第三方應用:
adb shell pm list packages -3
查看應用詳細信息
adb shell dumpsys package <pkg>
安裝 APK
adb install [-lrtsdg] <path_to_apk>
//直接安裝:adb install F:\...\demo.apk
參數 | 含義 |
---|---|
-r | 允許覆蓋安裝 |
-s | 將應用安裝到 sdcard |
-d | 允許降級覆蓋安裝 |
-g | 授予所有運行時權限sec |
卸載應用
adb uninstall <pkg>
清除應用數據與緩存
adb shell pm clear <pkg>
Activity
啓動Activity
adb shell am start <pkg>/<activity>
//打開設置頁面:adb shell am start com.android.settings/com.android.settings.Settings
停止Activity
adb shell am force-stop <pkg>
查看前臺 Activity
adb shell "dumpsys activity activities | grep mFocusedActivity"
發送廣播
adb shell am broadcast -a <broadcast>
//開機廣播:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
//發送指定廣播
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.test.demo/.BootCompletedReceiver
action | 廣播內容 |
---|---|
android.net.conn.CONNECTIVITY_CHANGE | 網絡連接發生變化 |
android.intent.action.SCREEN_ON | 屏幕點亮 |
android.intent.action.SCREEN_OFF | 屏幕熄滅 |
android.intent.action.BATTERY_LOW | 電量低,會彈出電量低提示框 |
android.intent.action.BATTERY_OKAY | 電量恢復了 |
android.intent.action.BOOT_COMPLETED | 設備啓動完畢 |
android.intent.action.DEVICE_STORAGE_LOW | 存儲空間過低 |
android.intent.action.DEVICE_STORAGE_OK | 存儲空間恢復 |
android.intent.action.PACKAGE_ADDED | 安裝了新的應用 |
android.net.wifi.STATE_CHANGE | WiFi 連接狀態發生變化 |
android.net.wifi.WIFI_STATE_CHANGED | WiFi 狀態變爲啓用/關閉/正在啓動/正在關閉/未知 |
android.intent.action.BATTERY_CHANGED | 電池電量發生變化 |
android.intent.action.INPUT_METHOD_CHANGED | 系統輸入法發生變化 |
android.intent.action.ACTION_POWER_CONNECTED | 外部電源連接 |
android.intent.action.ACTION_POWER_DISCONNECTED | 外部電源斷開連接 |
android.intent.action.DREAMING_STARTED | 系統開始休眠 |
android.intent.action.DREAMING_STOPPED | 系統停止休眠 |
android.intent.action.HEADSET_PLUG | 插入耳機 |
android.intent.action.MEDIA_UNMOUNTED | 卸載外部介質 |
android.intent.action.MEDIA_MOUNTED | 掛載外部介質 |
android.os.action.POWER_SAVE_MODE_CHANGED | 省電模式開啓 |
模擬按鍵文本)輸入
比如模擬點擊://在屏幕上點擊座標點x=100 y=200的位置。
adb shell input tap 100 200
按鍵點擊
adb shell input keyevent <keycode>
//Home鍵:
adb shell input keyevent 3
keycode | 含義 |
---|---|
3 | HOME 鍵 |
4 | 返回鍵 |
5 | 打開撥號應用 |
6 | 掛斷電話 |
24 | 增加音量 |
25 | 降低音量 |
26 | 電源鍵 |
27 | 拍照(需要在相機應用裏) |
62 | 空格 |
64 | 打開瀏覽器 |
66 | 確定 |
67 | 刪除 |
82 | 菜單鍵 |
85 | 播放/暫停 |
86 | 停止播放 |
87 | 播放下一首 |
88 | 播放上一首 |
126 | 恢復播放 |
127 | 暫停播放 |
164 | 靜音 |
176 | 打開系統設置 |
187 | 切換應用 |
207 | 打開聯繫人 |
208 | 打開日曆 |
210 | 打開計算器 |
220 | 降低屏幕亮度 |
221 | 提高屏幕亮度 |
223 | 系統休眠 |
224 | 點亮屏幕 |
276 | 如果沒有 wakelock 則讓系統休眠 |
輸入文本
在文本框輸入文本。
adb shell input text <text>
//adb shell input text hello
查看設備信息
adb shell cat /system/build.prop
型號
adb shell getprop ro.product.model
屏幕分辨率
adb shell wm size
//Physical size: 1920x1080
屏幕密度
adb shell wm density
//Physical density: 160
顯示屏參數
adb shell dumpsys window displays
系統版本
adb shell getprop ro.build.version.release
//6.0.1
IP 地址
adb shell "ifconfig | grep Mask"
CPU 信息
adb shell cat /proc/cpuinfo
內存信息
adb shell cat /proc/meminfo
重啓手機
adb reboot
使用 Monkey 進行壓力測試
//向指定的應用程序發送 100 個僞隨機事件。
adb shell monkey -p <pkg> -v 100