Android--ADB常用命令

无线连接
查看应用
安装 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_CHANGEWiFi 连接状态发生变化
android.net.wifi.WIFI_STATE_CHANGEDWiFi 状态变为启用/关闭/正在启动/正在关闭/未知
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含义
3HOME 键
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值