• Python Python实现批量安装android apk包


    基于Python实现批量安装android apk包

     

    by:授客 QQ1033553122

    1.相关软件包及文件下载

    下载地址:adb软件包及批量安装apk包的py文件.zip

     

    2.测试环境

    Win7 64

     

    Python 3.3.2

     

    3.用法及代码show

    用法:

    .apk包放入apk目录下,然后进入到install_apk_once_many.py所在目录,运行程序:

     

    python install_apk_once_many.py

     

    运行结果:

    Python <wbr>Python实现批量安装android <wbr>apk包




     

     

    代码展示

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-

    __author__ = 'shouke'

    import subprocess
    import os


    workdir = os.getcwd()
    apk_path = os.path.join(workdir, 'apk')
    adb_apth = os.path.join(workdir, 'adb.exe')

    p = subprocess.Popen(adb_apth + ' root', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
    try:
        p.communicate()
        if p.returncode:
            print('运行出错,程序已退出')
            exit()
    except Exception as e:
        p.kill()


    filename_list = os.listdir(apk_path)

    fail_cnt = 0   # 统计安装成功的包数
    pass_cnt = 0   # 统计安装失败的包数
    fail_list = [] # 存放安装失败的包文件名

    for filename in filename_list:
        if os.path.splitext(filename)[1] == '.apk': # 判断是否是apk包
            print('正在安装apk包:%s' % filename)
            p = subprocess.Popen(adb_apth + ' install -r apk/' + filename, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True) # adb install -r 如果已存在则覆盖安装
            try:
                outs = p.communicate()[0]
                if outs.find('Success'):
                    print('安装成功 ')
                    pass_cnt = pass_cnt + 1
                else:
                    print('安装失败 ')
                    fail_cnt = fail_cnt + 1
                    fail_list.append(filename)
            except Exception as e:
                p.kill()

    print('安装成功总数:', pass_cnt)
    print('安装失败总数:', fail_cnt)
    print ('安装失败的文件有:', fail_list)

     

    注:

    adb root   root权限重新启动 adb的守护进程

     

  • 相关阅读:
    交叉编译fw_printenv
    解压 xxxx.cpio.gz.u-boot
    创建Uboot 环境变量 bin 文件
    Linux快速显示图片
    移动终端的GPU显卡介绍
    Video Mode Timings
    change systemd service
    device tree DTB DTC 相互转换
    如何写出安全的API接口(参数加密+超时处理+私钥验证+Https)- 续(附demo)
    解决h5在ios 微信中 input框键盘收起 页面底部留白
  • 原文地址:https://www.cnblogs.com/shouke/p/10157607.html
Copyright © 2020-2023  润新知