Reputation: 41
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' ;
Upvotes: 3
Views: 1872
Reputation: 7390
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);
}
Upvotes: 1
Reputation: 1564
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.
Upvotes: 0