使用python编写脚本获取手机当前应用apk的信息
前提是已设置ANDROID_HOME环境变量,使用aapt工具获取apk的信息,保存至脚本所在目录下的PackageInfo.txt文件中:
importos
importtempfile
importre
tempFile=tempfile.gettempdir()
defget_aapt():
if"ANDROID_HOME"inos.environ:
rootDir=os.path.join(os.environ["ANDROID_HOME"],"build-tools")
forpath,subdir,filesinos.walk(rootDir):
if"aapt.exe"infiles:
returnos.path.join(path,"aapt.exe")
else:
return"ANDROID_HOMEnotexist"
defget_current_package_name():
pattern=re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
os.popen("adbwait-for-device")
out=os.popen("adbshelldumpsysinput|findstrFocusedApplication").read()
package_name=pattern.findall(out)[0].split("/")[0]
returnpackage_name
defget_match_apk(package_name):
list=[]
forpackagesinos.popen("adbshellpmlistpackages-f"+package_name).readlines():
list.append(packages.split(":")[-1].split("=")[0])
apk_name=list[0].split("/")[-1]
os.popen("adbpull"+list[0]+""+tempFile)
returntempFile+"\\"+apk_name
if__name__=="__main__":
os.popen(get_aapt()+\
"dumpbadging"+\
get_match_apk(get_current_package_name())+\
">PackageInfo.txt")
os.popen("del"+tempFile+"\\*.apk")热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短