本文主要介紹行動裝置測試過程中常用的一些adb 命令。詳見以下部分:
1. 查詢電腦連接了幾臺設備以及設備埠號:adb devices
2.進入9008模式:adb reboot edl
3.進入fastboot 模式:adb reboot bootloader
4.藍牙查詢,開關命令:
1)adb shell settings get global bluetooth_on 返回結果0代表關閉,1代表開啟
2)adb shell dumpsys bluetooth_manager | findstr enabled 返回結果true:開啟false:關閉
3)打開藍牙設置界面:adb shell am start -a android.settings.BLUETOOTH_SETTINGS
4)打開藍牙:adb shell svc bluetooth enable
5)關閉藍牙:adb shell svc bluetooth disable
5.查詢Wifi 是否開啟:adb shell settings get global wifi_on 返回0關閉,1:開啟
6.查詢WiFi地址:adb shell cat /sys/class/net/wlan0/address
7.打開wifi:adb shell svc wifi enable
8.關閉wifi :adb shell svc wifi disable
9.關閉\打開自動旋轉:adb shell settings put system accelerometer_rotation 0\1
10.獲取手機休眠時間:adb shell settings get system screen_off_timeout 單位S
11.修改手機休眠時間:adb shell settings put system screen_off_timeout 600000 10min
12.獲取系統默認輸入法:adb shell settings get secure default_input_method
13.列出輸入法:adb shell ime list -s
14.獲取手機是否為自動亮度:adb shell settings get system screen_brightness_mode (0代表非自動,1代表為自動)
15.設置手機為自動調整亮度:adb shell settings put system screen_brightness_mode 1
16.獲取手機當前亮度:adb shell settings get system screen_brightness 獲取值跟手機顯示不一致
17.設置手機亮度(0-255):adb shell settings put system screen_brightness 255
18. 打開定位設置界面:
adb shell am start -a android.settings.LOCATION_SOURCE_SETTINGS
19. 打開定位:adb shell settings put secure location_providers_allowed +gps
20. 撥打電話:adb shell am start -a android.intent.action.CALL tel:8888888888888
21. 發送簡訊:adb shell am start -a android.intent.action.SENDTO -d sms:10086(發送目的號碼) --es sms_body "hello"(簡訊內容) --ez exit_on_sent true
adb shell am start -a android.intent.action.SENDTO -d sms:10086 --es sms_body "hello" --ez exit_on_sent true
22. 清除應用數據和緩存:adb shell pm clear com.android.phone phone應用
23. 飛行模式:adb shell settings get global airplane_mode_on 0關閉,1開啟
24. 開啟飛行模式:adb shell settings put global airplane_mode_on 1 運行打開後數據不關閉
25. 手機震動測試(前提手機root):
①adb shell ②echo '3000'>/sys/devices/virtual/timed_output/vibrator/enable
26. 打開網頁:
adb shell am start -a android.intent.action.VIEW -d http://www.baidu.com
27. 獲取USB調試模式:adb shell settings get global adb_enabled
28. 關閉USB調試模式:adb shell settings put global adb_enabled 0 關閉之後需要到開發者選項中打開USB調試,否則電腦adb 連接不上手機
29. 向上滑動:adb shell input touchscreen swipe 930 880 930 380
30. 向右滑動:adb shell input touchscreen swipe 330 880 930 880 (adb shell input swipe 330 880 930 880)
31. 向左滑動:adb shell input swipe 930 880 330 880
32. 模擬滑鼠點擊操作:adb shell input mouse tap 100 500 ,adb shell input tap 100 500 點擊
33. 長按:adb shell input swipe 712 1960 663 1960 6000 6000毫秒
34. 滑動解鎖:adb shell input swipe 546 1980 472 630
35. 獲取電池信息:adb shell dumpsys battery
36. 切換手機電池為非充電狀態: adb shell dumpsys battery set status 1 重啟後才可以恢復充電
37. 修改手機電量為58%:adb shell dumpsys battery set level 58 ,可用第39個進行恢復
38. 修改電量到16:adb shell am broadcast -a "android.intent.action.BATTERY_CHANGED" --ei "status" 4 --ei "plugged" 0 --ei "level" 16
39.恢復手機電量:adb shell dumpsys battery reset *
40.查看手機當前電量:adb shell cat /sys/class/power_supply/battery/capacity
41.獲取手機型號:adb shell getprop ro.product.model
42.獲取屏幕解析度:adb shell wm size
43.獲取屏幕密度:adb shell wm density 如果顯示2行,表明修改過
44.顯示屏參數:adb shell dumpsys window displays
45.獲取手機IP位址:adb shell ifconfig | findstr Mask
46.查看WiFi區域網地址:adb shell ifconfig wlan0
47.查看通信日誌 :adb logcat -b radio (常用於查看詳細的通話狀態)
48.導出bugreport : adb pull /data/user_de/0/com.android.shell/files/bugreports 本地路徑
49.導出MTKlog: adb pull sdcard/debuglogger 本地路徑
50.導出tombstones: adb pull /data/tombstones 本地路徑
51.刪除tombstones: adb shell rm -rf /data/tombstones/
52.導出ANR 問題的trace文件:adb pull data/anr 本地路徑
53.導出kernel log:
adb logcat -v time -b kernel> C:\Users\wangqz\Desktop\temp\kernel.txt
54.導出event log:
adb logcat -v time -b events> C:\Users\wangqz\Desktop\temp\events.txt"
55.導出main log: adb logcat -v time >C:\Users\wangqz\Desktop\temp\main.txt
56.導出通信log:
adb logcat -v threadtime -b radio > C:\Users\wangqz\Desktop\temp\radio.txt
57.截圖bat:截圖到當前路徑:adb exec-out screencap -p > issue.png
58.錄視頻命令:adb shell screenrecord --size 1280x720 /sdcard/demo.mp4
59.導出錄製的視頻到當前目錄:
adb pull sdcard/demo.mp4 .\demo.mp4
60.修改溫度:
adb shell am broadcast -a "jp.kyocera.internal.devicemonitor.ThermalMonitor.action.TEMPERATURE_CHANGED" --ei "overheat_level" 256
61.高溫警告:嗶嗶的 警告音,震動:
adb shell "echo pullsel 052 0 > /sys/devices/platform/1000b000.pinctrl/mt_gpio"
62.查看連接過的wifi密碼:adb shell su cat /data/misc/wifi/*.conf
63.修改系統時間:adb shell su date -s 20200410.184000 修改系統時間為:2020年4月10號,18點40分00秒
64.輸入文本:adb shell input text hello 當焦點處於文本框時可以用此命令輸入文本
65.查看文件內容:adb shell cat sdacrd/1.txt 假設sdcard 裡面有個1.txt 的文件
66.刪除文件夾/文件:adb shell rm -rf sdcard/DCIM
67.新建文件夾:adb shell mkdir sdcard/down 在sdcard 目錄下建立down 文件夾
68.查看內存信息:adb shell cat /proc/meminfo
查看應用程式內存:adb shell dumpsys meminfo
查看CPU 信息:adb shell dumpsys cpuinfo
69.模擬back 按鍵:adb shell input keyevent 4 (4是back對應的鍵值),鍵值下一篇介紹
71.進入設備:adb shell adb -s devices 編號
連接多個設備時通過-s 來操作特定設備 ls-al :查看所有文件以及大小
72.獲取應用包名:adb shell dumpsys window|findstr mCurrentFocus
73.查看所有包名:adb shell pm list packages
74.查看應用安裝包位置: adb shell pm path 包名
75.打開熱點設置界面:adb shell am start -n com.android.settings/.TetherSettings
76. 清除logcat 緩存 adb shell logcat -c
以上命令若執行失敗,很大的可能是由於user版本存在權限的限制,可以用userdebug版本嘗試是否OK,
往期adb相關內容回顧:
monkey實戰-->測試步驟、常用參數、常規monkey命令
Android使用adb命令查詢包名和類名
簡談fastboot
Android 之無線adb連接