python自动安装apk文件

来源:互联网 发布:怎么用手机淘宝做代理 编辑:程序博客网 时间:2024/05/22 13:27

最近在学习python,在前一段时间用dos写了一脚本,自动安装apk文件,于是也试着用python写了一这样的脚本。

dos脚本地址:http://blog.csdn.net/lyhdream/article/details/14092351

前提条件,电脑中安装了python3.x.x的版本,创建一文件夹,放入要安装的所有apk文件,如下:


创建一文件以py为后缀,复制以下代码:

import osfiles = os.listdir(r'.') for file in files:   # print(file + str(len(file)) + "---" + file[1])   # print(file[len(file)-3:len(file)])   # print(file[len(file)-3:len(file)])    if file[len(file)-3:len(file)] == "apk":   #the string variable which is to storage the command  will excute later        string='adb install ' + "\"" + file + "\""        print(string)        os.system(string)

(注意:“\“” + file + "\"" , 这段代码,为了防止file的值含有空格,导致调用cmd命令安装失败,其次,apk不能为中文名,否则安装会出错)

双击文件,运行结果:

apk就已经安装到手机上了。

如果双击后出现:adb server is out of date.  killing .....的信息

则参考:

http://www.cnblogs.com/cuixiaodong427/archive/2013/04/20/3032106.html






原创粉丝点击