zoukankan      html  css  js  c++  java
  • 在多台手机上批量安装apk

    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()
    View Code

    结果就是:['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)
    View Code

    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()
    View Code

    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()
    View Code
  • 相关阅读:
    集群、分布式、负载均衡区别与联系
    Android--加载大分辨率图片到内存
    Android--MP3播放器MediaPlayer
    Android--SoundPool
    Android--MediaPlayer高级
    Android--调用系统照相机拍照与摄像
    Android--SurfaceView播放视频
    Android--使用VideoView播放视频
    Android--使用Camera拍照
    Vue组件选项props
  • 原文地址:https://www.cnblogs.com/rrl92/p/7655642.html
Copyright © 2011-2022 走看看