adb shell 常用命令

  1. 查看最上层成activity名字

    1
    2
    3
    4
    #linux:
    adb shell dumpsys activity | grep "mFocusedActivity"
    #windows:
    adb shell dumpsys activity | findstr "mFocusedActivity"
  2. 查看service列表

    1
    adb shell dumpsys activity services [包名(可选)]
  3. 查看window列表

    1
    adb shell dumpsys window
  4. 启动activity

    1
    2
    3
    4
    5
    6
    7
    adb shell am start -n <包名/完整类名> --es extra_key "extra_value"
    #(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据,等)
    #扩展数据类型:
    #-e String, int
    #--es String
    #--ez boolean
    #--ei int
  5. 启动service

    1
    2
    adb shell am startservice -n <包名/完整类名>
    #同启动activity一样也可以添加扩展数据
  6. 挂载/system 为可读写

    1
    2
    3
    adb shell
    su
    mount -o remount,rw /system
  7. 查看ip等网络信息

    1
    adb shell ifconfig
  8. kill adb服务
    有时候adb shel找不到设备,可以先杀掉adb服务再试试

    1
    adb kill-server
  9. kill adb进程
    有时候杀掉adb服务还是不行,可以尝试杀掉adb进程

    1
    2
    3
    4
    #linux
    killall adb
    #windows
    taskkill /f /im adb.exe
  10. 安装apk

    1
    adb install <apkfile>
  11. 卸载已安装的app

    1
    adb uninstall <package>
  12. 通过settings修改AndroidId

    1
    2
    3
    4
    5
    6
    #获取aid
    settings get secure android_id
    #修改aid
    settings put secure android_id [aid]
    #直接输入settings可查看使用说明
    settings
  13. 查看activity情况

    1
    adb shell dumpsys activity top