Skip to content

Instantly share code, notes, and snippets.

@zhEdward
Last active February 16, 2017 03:23
Show Gist options
  • Save zhEdward/8ddc0f5e84934fbe060ecd8d9922ad69 to your computer and use it in GitHub Desktop.
Save zhEdward/8ddc0f5e84934fbe060ecd8d9922ad69 to your computer and use it in GitHub Desktop.

For more adb-cheat-sheet follow this link

查看设备 ip地址

C:\Users\Edward\Desktop> adb -s Baytrail26AB2111 shell netcfg
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
p2p0     UP                                     0.0.0.0/0   0x00001003 02:09:4c:11:27:e5
wlan0    UP                                 192.110.1.4/24  0x00001043 00:09:4c:11:27:e5
rmnet2   DOWN                                   0.0.0.0/0   0x00000000 1e:f9:44:33:fc:5f
rmnet1   DOWN                                   0.0.0.0/0   0x00000000 5e:e0:a8:e2:bd:d4
rmnet0   DOWN                                   0.0.0.0/0   0x00000000 9e:5f:16:47:34:75

直接显示 wlan0 的ip地址(前提是wifi要已经连接上,否则获取失败)

C:\Users\Edward\Desktop> adb -s Baytrail26AB2111 shell ifconfig wlan0
wlan0: ip 192.110.1.4 mask 255.255.255.0 flags [up broadcast running multicast]

查看当前运行在最前端的 activity(微信为例)

//window
adb shell dumpsys activity package com.tencent.mm <| findstr mFocusedActivity> 
// linux/mac osx(支持快速查找某一字段)
$ adb shell dumpsys activity package com.tencent.mm <| grep mFocusedActivity>
...
    Running activities (most recent first):
      TaskRecord{22b73298 #9 A=com.tencent.mm U=0 sz=1}
        Run #2: ActivityRecord{22531450 u0 com.tencent.mm/.ui.LauncherUI t9}

    mResumedActivity: ActivityRecord{22531450 u0 com.tencent.mm/.ui.LauncherUI t9}

  mFocusedActivity: ActivityRecord{22531450 u0 com.tencent.mm/.ui.LauncherUI t9}
  //当前 处于最前面的activity

启动/强制关闭 app

#open app from cmd prompt 
$ adb [-s device_name] shell am -n <packageName>/<main-activity>

# force close app process from cmd prompt
$ adb [-s device_name] shell am force-stop <packageName>

PC与 android 设备之间 文件传输 pull/push

在需要root权限才可以操作的(/data/data/..)情况下 ,考虑使用先 cp 命令 把 文件拷贝到sdcard某一目录中,在尝试 pull 传输到 PC上

PC上文件拷贝到 android 设备sd卡中 adb push <local> <remote> - copy files/dirs to device

示例:

#上传文件 到 /sdcard/360 下
Edward@USER-EDWARD C:\Users\Edward\Desktop
> adb [-s device] push bids.xml /sdcard/360
[100%] /sdcard/360/bids.xml

#上传文件夹 到 sdcard/360/gittest 下 ,子文件夹不存在系统会自动创建
Edward@USER-EDWARD C:\Users\Edward\Desktop
> adb [-s device] push gittest /sdcard/360/gittest
adb: warning: skipping empty directory 'gittest\.git\objects\info\'
adb: warning: skipping empty directory 'gittest\.git\objects\pack\'
adb: warning: skipping empty directory 'gittest\android-swipe\AndroidSwipeLayout\.git\objects\info\'
adb: warning: skipping empty directory 'gittest\android-swipe\AndroidSwipeLayout\.git\refs\tags\'
/sdcard/360/gittest/: 1171 files pushed. 4 files skipped. 1.3 MB/s (29758211 bytes in 21.814s)

android internal sdcard文件拷贝到 PC上(PC上路径不存在会指定创建)

adb pull [-a] <remote> <local> - copy files/dirs from device
                                 (-a preserves file timestamp and mode)

示例:

#拷贝文件(不指定路径 默认当前操作cmd console 所指向的路径)
Edward@USER-EDWARD C:\Users\Edward\Desktop
> adb [-s device] pull /sdcard/Bluetooth1.1.apk
[100%] /sdcard/Bluetooth1.1.apk

# 拷贝文件夹(存在多个外设 只要 -s 指定设备)
Edward@USER-EDWARD C:\Users\Edward\Desktop
> adb -s 0123456789ABCDEF pull /sdcard/ktjx_stu/ketang/第1节 ./gittest
/sdcard/ktjx_stu/ketang/第1�/: 28 files pulled. 0 files skipped. 2.5 MB/s (15356016 bytes in 5.836s)
#乱码是 cmd console 显示问题

#在internal 中的文件 需要 使用
> shell@FX08_plus:/data/data/com.cpuid.cpu_z/lib # ls
libcpuid.so
> shell@FX08_plus:/data/data/com.cpuid.cpu_z/lib # cp libcupid.so /sdcard/libcupid.so

#退出到 PC上的cmd 使用如下命令把文件拷贝到 PC 上

Edward@USER-EDWARD C:\Users\Edward\Desktop
> adb pull /sdcard/libcupid.so .
[100%] /sdcard/libcpuid.so

查看android 设备的 CPU 架构(在安装 不用apk的时候 要根据cpu架构选择)

$ adb -s <one-devices> shell cat /proc/cpuinfo 
在输出的命令中 查找 Processor 字段(如果是山寨的,就只能 通过其他信息上网搜索)

查看设备硬件和系统属性(可以用在错误日志收集中)

$ adb shell cat /system/build.prop

使用 adb -s <device-name> shell getprop <属性名> 命令单独查看某个硬件信息,列举一部分属性如下:

属性名 含义
ro.build.version.sdk SDK 版本
ro.build.version.release Android 系统版本
ro.build.version.security_patch Android 安全补丁程序级别
ro.product.model 型号
ro.product.brand 品牌
ro.product.name 设备名
ro.product.board 处理器型号
ro.product.cpu.abilist CPU 支持的 abi 列表
persist.sys.isUsbOtgEnabled 是否支持 OTG
dalvik.vm.heapsize 每个应用程序的内存上限
ro.sf.lcd_density 屏幕密度

查看设备  分辨率 和 density

# 分辨率(通常是商家产品介绍中所说的分辨率)     
$ adb shell wm size
# e.g. 160 240 320 480 640
$ abd shell wm density

通用方法

$ adb <-s device-name> shell dumpsys window displays | grep init=

输出如下

 init=1536x2048 320dpi cur=2048x1536 app=2048x1440 rng=1536x1390-2048x1902

其中 init 是初始分辨率和屏幕密度,app 的高度比 init 里的要小,表示屏幕底部有虚拟按键,status bar 高度为 1920 - 1794 = 126px 合 42dp app 显示的参数 才是用在 dimen-?x?.xml 中进行特定分辨率适配用

查看 android 连接过的wifi 的密码(注意时效性),设备必须是可以获取root 权限

$ adb shell
$ su
$ cat /data/misc/wifi/*.conf

查看 android os version

$ adb -s <one-device> shell getprop ro.build.version.release

点亮/熄灭屏幕

#点亮屏幕
$ adb shell input keyevent 224
#熄灭屏幕
$ adb shell input keyevent 223
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment