使用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")热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下