3

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' ;

droidev
  • 7,352
  • 11
  • 62
  • 94
  • possible duplicate of [Resolving the package name of Android APK](http://stackoverflow.com/questions/6289149/resolving-the-package-name-of-android-apk) – dev2d Apr 16 '14 at 09:07

2 Answers2

1

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);
          }
droidev
  • 7,352
  • 11
  • 62
  • 94
0

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.

PankajSharma
  • 1,529
  • 14
  • 27