Pycharm--安装目录下的apk包

import os
import re,time
apkDir = r'C:\apk\\'
files = os.listdir(apkDir)

unInstallList = ['com.qihoo.cleandroid_cn','com.qihoo.cloudisk']
# 获得当前激活的应用包名
# adb shell dumpsys window w | findstr \/ | findstr name=

def ListDevice():
    rst = os.popen('adb devices').read()
    devices = re.findall(r'(.*?)\s+device', rst)
    if len(devices) > 1:
        devicesList = devices[1:]
    else:
        devicesList = []
    return devicesList

# 杀ADB服务
# os.system('adb kill-server')
# 重启usb服务
os.system('adb usb')
time.sleep(5)
# 等待至少一个设备连接
os.system('adb wait-for-device')
# 杀ADB进程
# taskkill = os.popen('taskkill /f /im adb.exe').read()
# print(taskkill)

devicesID = ListDevice()
print(devicesID)
time.sleep(5)
if len(devicesID) == 0:
    print("No Devices")
else:
    for i in devicesID:
        for j in unInstallList:
            # print('adb -s ' + i + ' uninstall ' + j)
            os.system('adb -s ' + i + ' uninstall ' + j)

        for file in files:
            if file[len(file) - 3:len(file)] == "apk":
                print(file)
                package = file
                packDir = apkDir + package
                # print('adb -s ' + i + ' install ' + packDir)
                os.system('adb -s ' + i +' install ' + packDir)
                time.sleep(5)

猜你喜欢

转载自blog.csdn.net/yu_chunhai/article/details/81218897