版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第python编写adb截图工具的实现源码目录一、功能二、使用说明三、实现1.初始源码2.优化:增加ip连接断开重连处理
一、功能
Android端或者Android终端的远程截图至本地电脑中
二、使用说明
1.adb截图工具可用于Android手机及Android终端
2.使用数据线连接前提:电脑与Android终端/手机已连接
Android终端/手机已打开开发者模式
3.生成的图片格式为png
三、实现
1.初始源码
importtime
importos,sys
defscreencap_cmd(filePath,devices=None):
iffilePath==None:
filePath='D:/png/'
ifnotos.path.exists(filePath):
os.makedirs(filePath)
filename=time.strftime("%Y%m%d%H%M%S",time.localtime())+".png"
ifdevices==None:
cmd_screencap='adbshellscreencap-psdcard/'+filename
cmd_pull='adbpullsdcard/'+filename+''+filePath+filename
cmd_delete='adbshellrmsdcard/'+filename
else:
cmd_screencap='adb-s'+devices+'shellscreencap-psdcard/'+filename
cmd_pull='adb-s'+devices+'pullsdcard/'+filename+''+filePath+filename
cmd_delete='adb-s'+devices+'shellrmsdcard/'+filename
os.system(cmd_screencap)
os.system(cmd_pull)
os.system(cmd_delete)
#保存地址判断及设备信息分类调用
defscreencap_info(devices=None,filePath=None):
iffilePath==None:
filePath='D:/png/'
ifnotos.path.exists(filePath):
os.makedirs(filePath)
ifdevices==None:
screencap_cmd(filePath)
adb_device_none(filePath)
else:
screencap_cmd(filePath,devices)
adb_info(devices,filePath)
#更换设备
defchange_devices():
r=os.popen("adbdevices")
lines=r.readlines()
lines=lines[1:-1]
n=len(lines)
foriinlines:
print(i.split("\t")[0])
devices=input("请输入指定设备:\n")
foriinlines:
ifdevicesini:
returndevices
print("未找到改设备请重新输入!")
change_devices()
#截图命令判断,电脑连接多个设备或使用IP截图时
defadb_info(lines,filePath=None):
s=input("是否截图(T/F/N)\n")
ifs=='t'ors=='T':
iffilePath==None:
screencap_info(lines)
else:
screencap_info(lines,filePath)
elifs=='N'ors=='n'ors=='exit':
sys.exit()
elifs=='F'ors=='f':
devices=change_devices()
iffilePath==None:
adb_info(devices)
else:
adb_info(devices,filePath)
#截图命令判断,电脑连接仅连接一个设备时
defadb_device_none(filePath=None):
s=input("是否截图(T/F/N)\n")
ifs=='t'ors=='T':
iffilePath==None:
screencap_info()
else:
screencap_info(None,filePath)
elifs=='N'ors=='n'ors=='exit':
sys.exit()
elifs=='F'ors=='f':
devices=change_devices()
iffilePath==None:
adb_info(devices)
else:
adb_info(devices,filePath)
#使用设备判断
defadb_devices(n,lines,filePath=None):
ifn==0:
print("请检查是否已接连或启动调试模式或安装adb环境")
s=input("再次启动(T/F)\n")
ifs=='t'ors=='T':
r=os.popen("adbdevices")
lines=r.readlines()
lines=lines[1:-1]
n=len(lines)
adb_devices(n,r.readlines())
else:
sys.exit()
elif":5555"inlines:
print("T:截图F:更换设备exit|N:退出")
iffilePath==None:
adb_info(lines)
else:
adb_info(lines,filePath)
elifn==1:
print("T:截图F:更换设备exit|N:退出")
iffilePath==None:
adb_device_none()
else:
adb_device_none(filePath)
elifn1:
foriinlines:
print(i.split("\t")[0])
devices=input("请输入指定设备:\n")
foriinlines:
ifdevicesini:
print("T:截图F:更换设备exit|N:退出")
iffilePath==None:
adb_info(devices)
else:
adb_info(devices,filePath)
print("未找到改设备请重新输入!")
iffilePath==None:
adb_devices(n,lines)
else:
adb_devices(n,lines,filePath)
#输入IP
defip_info():
ipPath=input("请输入IP:(不输入enter跳过默认使用数据线连接)\n")
iflen(ipPath)0:
try:
cnd='adbconnect'+ipPath
os.system(cnd)
returnipPath
except:
print("ADB调试模式为USB,需要切换到无线调试模式\n")
print("切换方法:\n第一步:Android设备开启USB调试,并且通过USB线连接到电脑\n第二步:在终端执行以下命令”adbtcpip5555“\n第三步:在终端执行以下命令”adbconnectip“。此时拔出USB线,应该就可以adb通过wifi调试设备\n")
returnip_info()
if__name__=='__main__':
ipPath=ip_info()
filePath=input("请输入保存地址:(不输入enter跳过,默认保存至D:\png\)\n")
#查询当前连接的设备
r=os.popen("adbdevices")
lines=r.readlines()
lines=lines[1:-1]
n=len(lines)
ip_add=0
ifipPath!=None:
foriinlines:
ifipPathini:
ip_add=i.split("\t")[0]
iflen(filePath)0:
if":\\"infilePath:
ifip_add!=0:
adb_devices(n,ip_add,filePath)
else:
adb_devices(n,lines,filePath)
else:
print("地址输入非法,使用默认地址\n")
ifip_add!=0:
adb_devices(n,ip_add)
else:
adb_devices(n,lines)
else:
ifip_add!=0:
adb_devices(n,ip_add)
else:
adb_device
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 通信企业社会责任指引
- 《PLC控制技术及应用》课件-知识延伸:展厅人数控制系统
- 《变流器运行与维护》课件-3.1 任务一 风力发电系统控制
- 新生儿黄疸的并发症预防
- 视网膜脱离术后疼痛管理护理查房
- 品质保障消费承诺书8篇范文
- 企业人力资源招聘与配置策略方案
- 家用电器产品使用安全承诺书7篇范文
- 心梗病人的护理措施
- 高血压病护理中的护理评估工具
- 数据出境安全协议
- 护士交接班礼仪
- 胰岛素抵抗病症典型症状及护理指南
- 利多卡因凝胶安全性分析-洞察及研究
- 水专题测试卷-高考地理二轮复习讲练测(解析版)
- 剪力墙渗水注浆施工方案
- 我国行政监督中存在的问题及其对策
- 我会自己晾衣服教案
- (粤教粤科2024版)科学二年级上册2.6 运用感觉器官 课件(新教材)
- 美丽的沙滩课件观看
- 低压电容柜维护手册
评论
0/150
提交评论