简体   繁体   English

从apk文件中提取包名称

[英]extract package name from apk file

In my java application, I have tried to get the package name of an android application. 在我的java应用程序中,我试图获取android应用程序的包名称。 I have tried it by executing command line argument. 我通过执行命令行参数尝试了它。 The command is : 命令是:

aapt dump badging <apk file>

And this command returned whole meta data of the application.I have to extract the package name from the returned string suppose named 'result' ; 并且此命令返回应用程序的整个元数据。我必须从返回的字符串中提取包名称,假设名为'result';

hoe you are looking for this try this code : 锄你正在寻找这个尝试这个代码:

String line;
        while ((line = r.readLine()) != null) {
            int ind = line.indexOf("package: name=");
            if (ind >= 0) {
                String yourValue = line.substring(ind + "default =".length(), line.length() - 1).trim(); // -1 to remove de ";"
                System.out.println(yourValue);
          }

Try this code.. 试试这个代码..

Get package name of application from apk file. 从apk文件获取应用程序的包名称。

All information from manifest 清单中的所有信息

aapt dump badging <path-to-apk>

Get only package name and main Activity Create applicationInfo.sh file with below data 仅获取包名称和主要活动创建具有以下数据的applicationInfo.sh文件

package=`aapt dump badging $* | grep package | awk '{print $2}' | sed s/name=//g | sed s/\'//g`
activity=`aapt dump badging $* | grep Activity | awk '{print $2}' | sed s/name=//g | sed s/\'//g`
echo
echo package : $package
echo activity: $activity

execute command as 执行命令为

<span class="skimlinks-unlinked">applicationInfo.sh</span> <path-to-apk>

This will print package name and main activity. 这将打印包名称和主要活动。 You can modify .sh file as per your need. 您可以根据需要修改.sh文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM