ADB基础命令

  1. 查看最顶端应用的包名和activity名

    adb shell dumpsys window | grep mCurrentFous	
    
  2. 操作指定设备

    # push 文件到指定设备的 /sdcard/中
    adb -s 设备id push aa.dex /sdcard/
    
  3. 查看手机log信息

    # 打印log
    adb logcat -i color
    
ADB 控制指令
  • 输入命令(input)
    adb shell input "111"
    
    • 特殊字符需要特殊的字符需要使用keyevnet
  • 模拟屏幕滑动(swip)
    adb shell input swipe 100 200 500 600 900  #从(100,200)滑动到(500,600)总花费900ms
    
  • 点击(tag)
    adb shell input tap 20 1000			# 点击(20, 100)
    
  • 长按(swip)
    adb shell input swipe 1400 400 1400 400 900  # 长按(1400,400) 900ms
    
  • 事件触发(keyevent)more
    adb shell input keyevent 7    # for key '0'
    adb shell input keyevent 8    # for key '1'
    adb shell input keyevent 29    # for key 'A'
    adb shell input keyevent 54    # for key 'B'
    adb shell input keyevent 26		# 电源键
    

    解锁手机:

    adb shell input keyevent 26 && adb shell input swipe 250 250 800 800
    

    截屏:adb exec-out screencap -p > 1.png

    adb shell screencap -p /sdcard/screen.png && adb pull /sdcard/screen.png /tmp/ && adb shell rm /sdcard/screen.png && open file:/tmp/screen.png
    

    Monkey点击

    adb shell monkey -p com.example.agsdkdemo 10000 -s500 -v
    

    自动化测试

    adb shell am instrument -w com.example.agsdkdemo.test/android.test.InstrumentationTestRunner
    

    获取厂商机型等

    adb shell getprop | grep product
    

    根据APK获取应用包名、权限配置等信息(配合grep)

    $ANDROID_HOME/build-tools/android-4.4/aapt d badging
    

    直接拉起应用

    adb shell am start -n com.example.wegame/com.example.wegame.MainActivity
    

    退出应用

    adb shell am force-stop com.example.wegame
    

    开启/关闭wifi

    adb shell svc wifi enable
    adb shell svc wifi disable