#encoding:utf-8
import os,time
#=======================查找手机设备序列号=============
a='adb devices'
b=os.popen(a).readlines()
#print(b)
l=[]
for sn in b:
if 'device' in sn and 'List' not in sn:
a=sn.split('\t')[0]
l.append(a)
print(l) #手机序列号列表
#==========================查找给定路径下,.apk文件========
def filep(fp):
apkl=[]
namel=os.listdir(fp)
for i in namel:
if os.path.splitext(i)[1]=='.apk':
apkl.append(i)
return apkl
#print(filep("E:\study\\apk"))
path="E:\study\\apk"
print(filep(path)) #.apk列表
#====================单个手机,循环安装apk==========
for onesn in l:
for apk in filep(path):
onepath=os.path.join(path,apk)
print(onepath)
a='adb -s {} install -r {}'.format(onesn,onepath)
print(a)
bb=os.popen(a).readlines()
time.sleep(3)
#print(bb)
if 'Success\n' in bb:
print('{} 手机的的{}已经安装完毕'.format(onesn,apk))
else:
print('==========={}手机的{}安装失败=========='.format(onesn,apk))
# time.sleep(2)
# os.system('adb shell input keyevent 4') #返回键
print('{}手机的所有apk已尝试安装'.format(onesn))
01-08 15:44
查看更多