Find package name for Android apps to use Intent to launch Market app from web
It depends where exactly you want to get the information from. You have a bunch of options:
- If you have a copy of the .apk, it's just a case of opening it as a zip file and looking at the AndroidManifest.xml file. The top level
<manifest>
element will have apackage
attribute. - If you have the app installed on a device and can connect using
adb
, you can launchadb shell
and executepm list packages -f
, which shows the package name for each installed apk. - If you just want to manually find a couple of package names, you can search for the app on http://www.cyrket.com/m/android/, and the package name is shown in the URL
- You can also do it progmatically from an Android app using the
PackageManager
Once you've got the package name, you simply link to market://search?q=pname:<package_name>
or http://market.android.com/search?q=pname:<package_name>
. Both will open the market on an Android device; the latter obviously has the potential to work on other hardware as well (it doesn't at the minute).
Use aapt
from the SDK like
aapt dump badging yourpkg.apk
This will print the package name together with other info.
the tools is located in
<sdk_home>/build-tools/android-<api_level>
or
<sdk_home>/platform-tools
or
<sdk_home>/platforms/android-<api_level>/tools
Updated according to geniusburger's comment. Thanks!
The following bash script can be used to display the package and activity names in an apk, and launch the application by passing it an APK file.
apk_start.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`echoecho package : $packageecho activity: $activityechoecho Launching application on device....echoadb shell am start -n $package/$activity
Then to launch the application in the emulator, simply supply the APK filename like so:
apk_start.sh /tmp/MyApp.apk
Of course if you just want the package and activity name of the apk to be displayed, delete the last line of the script.
You can stop an application in the same way by using this script:
apk_stop.sh
package=`aapt dump badging $* | grep package | awk '{print $2}' | sed s/name=//g | sed s/\'//g`adb shell am force-stop $package
like so:
apk_stop.sh /tmp/MyApp.apk
Important Note: aapt can be found here:
<android_sdk_home>/build-tools/android-<ver>/aapt