1.手机要打开adb调试
2.该程序可以实现台android手机的多个apk批量安装
1.getSeriaoNum.py模块,该模块获取已连接手机的序列号
import os import threading import time import adbModule import getSeriaoNum class InstallApk(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): arrayDev = [] arrayApkPackage = [r'C:UsersliangraoraoDesktopapkiBiliPlayer-bili.apk'] while True: udid_list = getSeriaoNum.get_devices() for udid in udid_list: if udid in arrayDev: continue adbModule.InstallApk(udid, arrayApkPackage).start() arrayDev.append(udid) if len(arrayDev) > 10: arrayDev.clear() #需要安装的手机数量==已经安装的手机数量,结束循环 num = len(getSeriaoNum.get_devices()) if len(arrayDev) == num: break time.sleep(10) InstallApk().start()
结果就是:['1713d0b20204', '192.168.1.101:5555']
2.adbModule.py 封装安装和卸载的adb命令
1 import threading 2 import os 3 """ 4 arrayApkPackage: 要安装的apk列表 5 arrayPackageName:要卸载的apk包名 6 """ 7 8 class InstallApk(threading.Thread): 9 def __init__(self, udid, arrayApkPackage): 10 threading.Thread.__init__(self) 11 self.udid = udid 12 self.arrayApkPackage = arrayApkPackage 13 14 def run(self): 15 for apkPackage in self.arrayApkPackage: 16 os.popen('adb -s' + self.udid + ' install -r '+apkPackage) 17 18 class UnstallApk(threading.Thread): 19 def __init__(self, udid, arrayPackageName): 20 threading.Thread.__init__(self) 21 self.udid = udid 22 self.arrayPackageName = arrayPackageName 23 24 def run(self): 25 for packageName in self.arrayPackageName: 26 os.popen('adb -s'+ self.udid +' uninstall '+packageName)
3.ExeInstall.py 批量安装apk模块
1 import os 2 import threading 3 import time 4 import adbModule 5 import getSeriaoNum 6 7 8 class InstallApk(threading.Thread): 9 def __init__(self): 10 threading.Thread.__init__(self) 11 12 def run(self): 13 arrayDev = [] 14 arrayApkPackage = [r'C:UsersadminDesktopapkiBiliPlayer-bili.apk'] 15 while True: 16 udid_list = getSeriaoNum.get_devices() 17 for udid in udid_list: 18 if udid in arrayDev: 19 continue 20 adbModule.InstallApk(udid, arrayApkPackage).start() 21 arrayDev.append(udid) 22 if len(arrayDev) > 10: 23 arrayDev.clear() 24 25 #需要安装的手机数量==已经安装的手机数量,结束循环 26 num = len(getSeriaoNum.get_devices()) 27 28 if len(arrayDev) == num: 29 break 30 time.sleep(10) 31 32 InstallApk().start()
4.ExeUninstall.py 批量卸载apk
1 import threading 2 import os 3 import getSeriaoNum 4 import adbModule 5 6 class UnintallApk(threading.Thread): 7 def __init__(self): 8 threading.Thread.__init__(self) 9 10 def run(self): 11 arrayDev = [] 12 arrayPackageName = ['tv.danmaku.bili'] 13 while True: 14 udid_list = getSeriaoNum.get_devices() 15 for udid in udid_list: 16 if udid in arrayDev: 17 continue 18 adbModule.UnstallApk(udid, arrayPackageName).start() 19 arrayDev.append(udid) 20 if len(arrayDev) > 10: 21 arrayDev.clear() 22 23 #需要安装的手机数量==已经安装的手机数量,结束循环 24 num = len(getSeriaoNum.get_devices()) 25 26 if len(arrayDev) == num: 27 break 28 time.sleep(10) 29 30 UnintallApk().start()