python获取安卓包名与activity方法

代码如下:


def adbcmdapk(filepath):
    if not os.path.exists(filepath):
        return 0
    getPackageActivity = 'aapt d badging %s |findstr "package launchable-activity"' % (filepath)
    result = os.popen(getPackageActivity).readlines()
    packageandpackage = {}
    package = ""
    activity = ""
    for i in range(len(result)):
        if "package" in result[i]:
            nameNumber = result[i].find("e='")
            versionCodeNumber = result[i].find("' v")
            package = result[i][nameNumber + 3:versionCodeNumber]
        if "launchable-activity" in result[i]:
            nameNumber = result[i].find("e='")
            versionCodeNumber = result[i].find("'  l")
            activity = result[i][nameNumber + 3:versionCodeNumber]
        # 添加到字典中
        packageandpackage[package] = activity
    return packageandpackage

测试类


if __name__ == '__main__':
    pa = "E:\\toontest3.8.1.apk"
    print(adbcmdapk(pa))

结果:

{'com.systoon.toon': 'com.systoon.toon.user.login.view.WelcomeActivity'}

高坪ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

第二种方式:

class ApkInfo():
    def __init__(self, apkPath):
        self.apkPath = apkPath

     def getApkBaseInfo(self):
        p = subprocess.Popen("aapt dump badging %s" % self.apkPath, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE, shell=True)
        (output, err) = p.communicate()
        match = re.compile("package: name='(\S+)' versionCode='(\d+)' versionName='(\S+)'").match(output.decode())
        if not match:
            raise Exception("can't get packageinfo")
        packagename = match.group(1)
        versionCode = match.group(2)
        versionName = match.group(3)

        print('packagename:' + packagename)
        print('versionCode:' + versionCode)
        print('versionName:' + versionName)
        return packagename, versionName, versionCode

if name== 'main':
ApkInfo(r"E:\toontest3.8.1.apk").getApkBaseInfo()

结果:

packagename:com.systoon.toon
versionCode:1803060450
versionName:3.8.1


网站名称:python获取安卓包名与activity方法
URL地址:http://hbruida.cn/article/gdgsdh.html