詳解android adb常見用法
ADB,即 Android Debug Bridge,是 Android 開發(fā)/測試人員不可替代的強大工具。
adb與應(yīng)用的連接1.啟動/停止啟動 adb server 命令:
adb start-server
(一般無需手動執(zhí)行此命令,在運行 adb 命令時若發(fā)現(xiàn) adb server 沒有啟動會自動調(diào)起。)
停止 adb server 命令:
adb kill-server2.查看 adb 版本
命令:
adb version
輸出為:
C:WINDOWSsystem32>adb versionAndroid Debug Bridge version 1.0.41Version 29.0.6-6198805Installed as E:programandroid-sdk_r24.4.1-windowsandroid-sdk-windowsplatform-toolsadb.exe
3.查看已連接設(shè)備adb devices
輸出為:
C:WINDOWSsystem32>adb devicesList of devices attachedCVH7N16A12000234 device
顯示屏參數(shù)1.android_idadb shell settings get secure android_id2.android系統(tǒng)版本
adb shell getprop ro.build.version.release3.分辨率
adb shell wm size
輸出為:
C:WINDOWSsystem32>adb shell wm sizePhysical size: 1440x2560
4.密度adb shell wm density
輸出為:
Physical density: 560
5.顯示屏參數(shù)adb shell dumpsys window displays
其中 mDisplayId 為 顯示屏編號,init 是初始分辨率和屏幕密度,app 的高度比 init 里的要小,表示屏幕底部有虛擬按鍵
adb與應(yīng)用交互1.查看前臺 Activityadb shell dumpsys activity | findstr 'mFocusedActivity'
獲取完整路徑:
adb shell dumpsys window | findstr mCurrentFocus2.查看正在運行的Services
adb shell dumpsys activity services [packagename]3查看應(yīng)用詳細信息
adb shell dumpsys package [packagename]command 用途 start [options] 啟動 Activity startservice [options] 啟動 Service broadcast [options] 發(fā)送廣播 force-stop 停止進程
用于決定intent對象的選項如下:
參數(shù) 作用 -a 指定action,比如 android.intent.action.VIEW -c 指定 category,比如 android.intent.category.APP_CONTACTS -n 指定完整 component 名,用于明確指定啟動哪個 Activity,如 com.example.app/.ExampleActivity -W 輸出完整的打開應(yīng)用過程am(Activity Manager)命令來啟動一個APP、啟動Activity、啟動廣播和服務(wù)等
4.啟動應(yīng)用adb shell am start xx
舉例:
C:WINDOWSsystem32>adb shell am start -W com.tencent.mobileqq/com.tencent.mobileqq.activity.SplashActivityStarting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.tencent.mobileqq/.activity.SplashActivity }Warning: Activity not started, its current task has been brought to the frontStatus: okActivity: com.tencent.mobileqq/.activity.SplashActivityThisTime: 2916TotalTime: 2916WaitTime: 2936Complete5.啟動Service
adb shell am startservice 'com.example.crime/com.example.crime.MyService'6.停止Service
adb shell am stopservice [options] <INTENT>7.發(fā)送廣播
adb shell am broadcast -a 'our.specified.action'8.強制停止應(yīng)用
adb shell am force-stop com.qihoo360.mobilesafe9.查看應(yīng)用安裝路徑
adb shell pm path (PACKAGE)
舉例:
C:WINDOWSsystem32>adb shell pm path com.tencent.mobileqqpackage:/data/app/com.tencent.mobileqq-xt0XnDpe7yq8Z5YGef0iEA==/base.apk10.查看手機應(yīng)用
adb shell pm list packages
可在 adb shell pm list packages 的基礎(chǔ)上可以加一些參數(shù)進行過濾查看不同的列表,支持的過濾參數(shù)如下:
參數(shù) 顯示列表 無 所有應(yīng)用 -f 顯示應(yīng)用關(guān)聯(lián)的apk文件 -d 只顯示disabled的應(yīng)用 -e 只顯示enabled的應(yīng)用 -s 只顯示系統(tǒng)應(yīng)用 -3 只顯示第三方應(yīng)用 -i 顯示應(yīng)用的 installer -u 包含已卸載應(yīng)用舉例:1.打印第三方應(yīng)用的列表
adb shell pm list package -3
輸出為:
C:WINDOWSsystem32>adb shell pm list package -3package:com.quark.browserpackage:com.safervpn.androidpackage:de.blinkt.openvpnpackage:com.zhiliaoapp.musically.gopackage:net.ivpn.clientpackage:com.networkprotect.ultravpnpackage:com.google.android.apps.docs.editors.docspackage:com.expressvpn.vpnpackage:com.sharpvpn.freefast_ipchangerpackage:com.whatsapppackage:com.google.android.apps.docs.editors.sheetspackage:com.google.android.apps.docs.editors.slidespackage:com.digitanlabs.apps.supervpnpackage:com.gaditek.purevpnicspackage:com.speedify.speedifyandroidpackage:net.hideman.freepackage:net.safemove.android.cippackage:com.securitykiss.androidpackage:im.zpn
2.包名含有某字符的應(yīng)用
C:WINDOWSsystem32>adb shell pm list packages tencentpackage:com.tencent.mmpackage:com.tencent.qqlivei18npackage:com.tencent.mobileqq
當然也可以用管道符來過濾:
C:WINDOWSsystem32>adb shell pm list packages | findstr tencentpackage:com.tencent.mmpackage:com.tencent.qqlivei18npackage:com.tencent.mobileqq11.安裝apk
adb install xx.apk
允許覆蓋安裝:
adb install -r xx.apk12.卸載apk
adb uninstall com.tencent.mobileqq
卸載并保留數(shù)據(jù):
adb uninstall -k com.tencent.mobileqq13.指定adb server的網(wǎng)絡(luò)端口
adb -P <port> start-server文件管理1.復制設(shè)備里的文件到電腦
adb pull <設(shè)備里的文件路徑> [電腦上的目錄]
其中 電腦上的目錄 參數(shù)可以省略,默認復制到當前目錄。
2.復制電腦里的文件到設(shè)備adb push <電腦上的文件路徑> <設(shè)備里的目錄>事件輸入1.模擬按鍵操作
adb shell input keyevent < keycode >
不同的 keycode 能實現(xiàn)不同的功能,列表如下:
keycode: 含義 3HOME 鍵4返回鍵5打開撥號應(yīng)用6掛斷電話24增加音量25降低音量26電源鍵27拍照(需要在相機應(yīng)用里)64打開瀏覽器82菜單鍵85播放/暫停86停止播放87播放下一首88播放上一首122移動光標到行首或列表頂部123移動光標到行末或列表底部126恢復播放127暫停播放164靜音176打開系統(tǒng)設(shè)置187切換應(yīng)用207打開聯(lián)系人208打開日歷209打開音樂210打開計算器220降低屏幕亮度221提高屏幕亮度223系統(tǒng)休眠224點亮屏幕231打開語音助手276如果沒有 wakelock 則讓系統(tǒng)休眠
亮屏熄屏:
adb shell input keyevent 262.滑動屏幕
adb shell input swipe x1 y1 x2 y2
參數(shù)分別表示:起始點x坐標 起始點y坐標 結(jié)束點x坐標 結(jié)束點y坐標
3.輸入文本adb shell input text 1234.模擬屏幕點擊事件
adb shell input tap 500 500事件輸出1.日志信息:
使用adb logcat可以顯示日志信息
2.dumpsys:dumpsys命令可以提供非常多的系統(tǒng)信息。可以通過adb shell service list來查看dumpsys能提供查詢信息的服務(wù)。列舉幾個:查看電池信息
adb shell dumpsys battery
查看鬧鐘信息
adb shell dumpsys alarm3.截屏
adb shell screencap /imgpath/screen.png4.錄屏
adb shell screenrecord /imgpath/demo.mp4
imgpath可以根據(jù)自己相冊里面的照片路徑信息獲取
以上就是詳解android adb常見用法的詳細內(nèi)容,更多關(guān)于android adb用法的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
