Android - 常用adb命令总结

文章目录


前言

自己总结,方便自己使用


一.常用adb命令

1.查询已连接设备

adb devices

2.获取设备状态(devices:正常连接,iffline:连接异常设备无响应,unknown:没有连接)

adb get-state

3.获取电脑安装的adb版本号和路径

adb version

4.apk安装卸载(apk名称和路径不能有中文)

adb install xxx/xxx.apk
adb uninstall com.app.xxx(应用包名)

5.启动/关闭adb服务

adb start-server
adb kill-server

6.文件复制

从安卓设备复制到电脑:

adb pull sdcard/xxx.txt d:\
从电脑复制到安卓设备:
adb push d:\xxx.txt sdcard/

7.重启设备

重启

adb reboot

重启进入recovery模式

adb reboot recovery

重启进入fastboot模式

adb reboot bootloader

8.进入刷机模式

MTK平台:

adb reboot fastboot

RK平台:

adb reboot loader

9.WiFi连接adb

a.电脑和安卓设备处于同一局域网下
b.安卓设备进入开发者模式打开WiFi调试
c.电脑端执行adb connect 192.168.1.102(安卓设备IP)

10.抓取log

adb logcat > d:\xxx.txt

11.获取root权限

adb root

12.重新挂载设备

adb remount

二.常用adb shell命令

pm命令:

1.列出设备所有应用包名

adb shell pm list package

2.列出系统应用

adb shell pm list package -s

3.列出第三方应用

adb shell pm list package -3

4.列出应用包名/apk名/存放位置

adb shell pm list package -f

5.列出指定应用的dump信息

adb shell pm dump com.tencent.mobileqq

6.关键字筛选(windows上用findstr,在Linux上用grep),在命令最后加 | findstr 内容XXX

adb shell pm list package -f | findstr gps

7.安装卸载存放在安卓设备上的apk

adb shell pm install sdcard/xxx.apk
adb shell pm uninstall com.xxx.xxx.apk  ---与adb uninstall相同

8.清除应用缓存

adb shell pm clear com.app.xxx

9.设置/获取应用安装位置

[0/auto]:默认为自动
[1/internal]:默认为安装在手机内部
[2/external]:默认安装在外部存储

获取:

adb shell pm get-install-location

设置:

adb shell pm set-install-location 0

10.列出设备所有权限

adb shell pm list permissions -f

11.列出设备用户

adb shell pm list users -f 

am命令:

1.MTK平台进入log设置界面

adb shell am start -n com.mediatek.mtklogger/com.mediatek.mtklogger.MainActivity

2.启动一个activity

adb shell am start -n com.android.camera/.Camera Starting: Intent { cmp=com.android.camera/.Camera }

3.启动默认浏览器打开一个网页

adb shell am start -a android.intent.action.VIEW -d http://testerhome.com

4.启动拨号器拨打 10086

adb shell am start -a android.intent.action.CALL -d tel:10086 

5.监控 crash 与 ANR

adb shell am monitor

6.启动一个 instrumentation , 单元测试或者 Robotium 会用到

adb shell am instrument

7.结束应用,com.example.filetorw为包名

adb shell am force-stop com.example.filetorw

8.启动一个服务

adb shell am startservice -n  {包(package)名}/{包名}.{服务(service)名称}

例:
adb shell am startservice -n com.example.servicetest/com.example.servicetest.MyService

9.发送一个广播

发送一个网络变化的广播

adb shell am broadcast -a android.net.conn.CONNECTIVITY_CHANGE

10.回到桌面

adb shell am start -n com.android.launcher3/com.android.launcher3.Launcher

11.进入设置界面

adb shell am start -n com.android.settings/.Settings

input命令

1.发送文本内容,不能发送中文

adb shell input text test123456

2.发送按键事件

按下home键

adb shell input keyevent KEYCODE_HOME

按下back键

adb shell input keyevent BACK

点亮/熄灭手机屏幕,说明:keyevent 后面数字是键值,26代表手机电源键

adb shell input keyevent 26

3.对屏幕发送一个触摸事件,tap后面为触摸点的坐标

adb shell input tap 500 500

4.对屏幕发送一个滑动事件,swipe后面依次为起点坐标,终点坐标

adb shell input swipe 900 500 100 500

其他命令

1.截图命令

adb shell screencap -p /sdcard/screen.png

2.屏幕录制命令,最多录制3分钟自动停止,如需提前停止ctrl + c 结束录制

adb shell screenrecord sdcard/record.mp4

3.获取当前界面控件信息,会生成一个xml文件默认存放在sdcard下

adb shell uiautomator dump

4.列出设备上的输入法

adb shell ime list -s

输出结果:
com.baidu.input_mi/.ImeService

5.设置指定的输入法

adb shell ime set com.baidu.input_mi/.ImeService

6.获取设备分辨率

adb shell wm size

7.打开整机monkey并保存log到sdcard中,正常日志和异常日志分开保存

一定要先执行adb shell,在执行后面的monkey命令,否则无法再sdcard中创建日志文件

adb shell 
monkey -s 1000 --pct-syskeys 0 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --pct-trackball 0 --pct-nav 0 --pct-majornav 0 --pct-anyevent 0 -v -v -v --throttle 500 1800000000 1>/sdcard/Monkey1.txt 2>/sdcard/Monkey2.txt 

8.打开相机monkey并保存log到sdcard中,正常日志和异常日志分开保存

adb shell
monkey -p com.android.camera2 -s 1000 --pct-syskeys 0 --ignore-crashes --ignore-timeouts --ignore-security-exceptions -v -v -v --throttle 1000 1000000 1>/sdcard/CameraMonkey1.txt 2>/sdcard/CameraMonkey2.txt

9.查看 Android 设备的参数信息,结果以 key : value 键值对的形式显示

adb shell getprop

10.获取CPU型号等信息,HardWare后面的就是CPU的型号

adb shell cat /proc/cpuinfo

11.导出设备信息

导出设备序列号

adb get-serialno > aaa.txt

导出MAC地址

adb shell cat /sys/class/net/wlan0/address > aaa.txt

导出设备型号

adb shell getprop ro.product.model > aaa.txt

导出系统版本

adb shell getprop ro.build.version.release> aaa.txt

导出屏幕分辨率

adb shell wm size > aaa.txt

导出屏幕密度

adb shell wm density > aaa.txt

导出CPU信息

adb shell cat /proc/cpuinfo > aaa.txt

12.打开TP划线

1是打开画线 ,0是关闭

 adb shell settings put system pointer_location 1

13.打开TP小白点

1是打开,0是关闭

 adb shell settings put system show_touches 1

14.读写时间同步服务器ntp

读取系统ntp服务器地址:

adb shell settings get global ntp_server

设置系统ntp服务器地址为 ntp1.aliyun.com:

adb shell settings put global ntp_server ntp1.aliyun.com

15.打开蓝牙

adb shell service call bluetooth_manager 6
或
adb shell service call bluetooth_manager 6 s16 "com.android.bluetooth"

16.关闭蓝牙

adb shell service call bluetooth_manager 8
或
adb shell service call bluetooth_manager 8 s16 "com.android.bluetooth" i32 1

17.查看蓝牙信息

adb shell dumpsys bluetooth_manager

18.获取蓝牙开关状态

返回1表示开启,0表示关闭
adb shell settings get global bluetooth_on

总结

以上就是今天要讲的内容,本文仅仅简单介绍了adb常用的一些命令,而adb还有大量不常用的命令,有需要可自行研究

  • 4
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值