Question

In my java application, I have tried to get the package name of an android application. 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' ;

Was it helpful?

Solution

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);
          }

OTHER TIPS

Try this code..

Get package name of application from apk file.

All information from manifest

aapt dump badging <path-to-apk>

Get only package name and main Activity Create applicationInfo.sh file with below data

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top