adb三种使用方式 cmd+bat+python

本文旨在分享adb的三种使用技巧,cmd+bat+python

1.cmd 最简单的方式,在任意路径输入cmd回车,或者window+r等方式打开 命令提示符,直接输入adb命令既可以使用

adb devices

显示为 :List of devices attached

192.168.1.11:5555 device

2.bat格式 新建一个文本文件,输入下面的内容,重新命名为”截图.bat”然后双击既可以(这里先adb连接成功设备)。太久了忘记了是否先需要转码,如果需要就用notepad++把编码转为ANSI,微信发给别人的时候,一定是要转码的。

@echo off
set /p a=请输入:
adb shell screencap   -p /sdcard/%a%.png
adb pull /sdcard/%a%.png C:\Users\Administrator\Desktop\图片
adb shell rm -rf /sdcard/%a%.png
echo. & pause

3.python格式 ,bat格式好用是好用,命令封装好了,直接运行就行,但是我用了一段时间发现,连个截图的命令都快忘记了,就想到是否可以用python直接调用cmd,结果是肯定的。使用subproces这个python内置库即可,也就是免pip安装第三方库了。下面贡献一些常用命令。

a='adb devices'
b='adb connect 192.168.1.92'               #请确认wifi是否连接成功              #请确认wifi是否连接成功
d='adb disconnect 192.168.1.142'
c='adb shell pm clear zhiyun.com.mirrorplusandroid'   #清理 包的缓存/内存.standalone
c2="adb shell  pm  clear  zhiyun.com.mobile"
e='adb shell getprop ro.serialno'     # 查询序列号
t='adb install  -r -d -t  '+ r'E:\a软件安装包\测试版\351测试版\a1.apk'
tt='adb uninstall  -r -d -t  '+ r'E:\a软件安装包\测试版\351测试版\a1.apk'
aaaa="adb shell logcat -c "  #-ai http://pypai.douban.com/simple --trusted-host pypi.douban.com
aaa='adb shell  logcat  -v  time  >' + r'C:\Users\Administrator\Desktop\aa.txt'
mk='adb shell monkey -p zhiyun.com.mirrorplusandroid --ignore-crashes --ignore-timeouts --throttle 300 -vvv --pct-touch 60 --pct-motion 35 5000000 1> 'r'C:\Users\Administrator\Desktop\1.txt' ' 2>' r'C:\Users\Administrator\Desktop\2.txt'
cmd=   'adb tcpip 5555'
if "'"  or '"' not in cmd:
    cmd   =      c2
def run_cmd_Popen_fileno(cmd_string):
    import subprocess
    return subprocess.Popen(cmd_string, shell=True, stdout=None, stderr=None).wait()
run_cmd_Popen_fileno(cmd)
q="adb kill-server"
p="adb shell ps | findstr zhiyun.com.mirrorplusandroid"
o="adb shell top"
k="adb shell kill 3668   "
s="adb shell ps   | findstr  uiautom "
z='adb shell dumpsys window | findstr init'    #查看分辨率   mDisplayId 为 显示屏编号,init 是初始分辨率和屏幕密度,app 的高度比 init 里的要小,表示屏幕底部有虚拟按键,高度为 1920 - 1794 = 126px 合 42dp。
zz='adb shell dumpsys window displays'
ac='adb logcat -s ActivityManager'  #  Activity的启动时间
g='adb shell pm list packages -3'      #查看设备的所有第三方包名
# dd=input("请输入照片名字:")
# adb shell screencap   -p /sdcard/%a%.png
# adb pull /sdcard/%a%.png C:\Users\Administrator\Desktop\图片
# adb shell rm -rf /sdcard/%a%.png
# d='adb pull /sdcard/'+dd+'.png'  r"C:\Users\Administrator\Desktop\图片"
w='python -m weditor' #python -m uiautomator2 init
# ff=r''
# f='adb pull /sdcard/'+ff+'.png '+r'C:\Users\Administrator\Desktop\图片'
def run_cmd( cmd_str=a, echo_print=1):
    """    执行cmd命令,不显示执行过程中弹出的黑框
    备注:subprocess.run()函数会将本来打印到cmd上的内容打印到python执行界面上,所以避免了出现cmd弹出框的问题
    :param cmd_str: 执行的cmd命令  :return:    """
    from subprocess import run
    if echo_print == 1:
        print('\n执行cmd指令="{}"'.format(cmd_str))
        print(" ")
    run(cmd_str, shell=True)
  1. 还有最后一种,把adb封装成一个界面小工具,具备常用命令一键运行,编辑。目前设计加上显示输出结果(未实现),保存日志,多命令集成运行,由于本人技术有限,欢迎大家讨论,也欢迎大家二次开发,需要的人可以找我要代码,太多了。

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值