Is there a way I can get application name, application version and application icon, for the package that is not yet installed? (for some apk file on sdcard)
5 Answers
I just spent more hours than I'll ever admit looking for the solution to this.. and found it! :) :)
After wandering into this reference: http://code.google.com/p/android/issues/detail?id=9151 I found out the trick to obtaining the icon and name(label, that is) from .apk files that have NOT BEEN INSTALLED.
I hope it's not too late to help others with this:
String APKFilePath = "mnt/sdcard/myapkfile.apk"; //For example...
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// the secret are these two lines....
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
//
Drawable APKicon = pi.applicationInfo.loadIcon(pm);
String AppName = (String)pi.applicationInfo.loadLabel(pm);
After light testing this, it seems to work... whew.

- 1,189
- 10
- 15
-
Must be Must be Must be market as CORRECT answer :D helped a lot thanks :) – AZ_ Mar 17 '14 at 09:50
-
2
-
@ShirishHerwade It's already inside "pi" variable. version code: http://developer.android.com/reference/android/content/pm/PackageInfo.html#versionCode , version name: http://developer.android.com/reference/android/content/pm/PackageInfo.html#versionName – android developer Sep 01 '14 at 21:35
-
-
These two secret lines left the `APKFilePath` open. How to close the file? – damgad Aug 30 '16 at 14:43
-
-
I have tried:
PackageInfo info = getPackageManager().getPackageArchiveInfo(fullPath, 0);
ApplicationInfo appinfo = info.applicationInfo;
label = getPackageManager().getApplicationLabel(appinfo).toString();
img = getPackageManager().getApplicationIcon(info.packageName);
But if the apk isn't installed this code won't work.
I can get apk icon, version, name by using getPackageArchiveInfo(archiveFilePath, flags)
and getApplicationIcon (ApplicationInfo info)

- 38,970
- 17
- 111
- 142

- 5,669
- 7
- 58
- 90
-
7Doesn't work for apps that are not installed :(, only returns the default app icon. – Ragunath Jawahar Jul 30 '11 at 21:19
-
This shouldn't be an accepted answer as this does not answer the question. @POMATu please mark the answer by Tam as the accepted answer – Phani Rithvij Oct 23 '19 at 19:52
// Install a known apk file from the SD-Card
// or launch it if installed.
// -hsigmond
protected void runAppFromApkFileOnSdCard() {
final PackageManager pm = getActivity().getPackageManager();
String apkFileName = "application_name.apk";
String fullPath = "/sdcard/"+apkFileName;
PackageInfo packageInfo = pm.getPackageArchiveInfo(fullPath, 0);
Intent intent = pm.getLaunchIntentForPackage(packageInfo.packageName);
if( intent == null ){
File file = new File(fullPath);
intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
}
startActivity(intent);
}
Use:
packageInfo.applicationInfo.['name','icon','logo'] etc.
Example Icon:
Drawable icon = packageInfo.applicationInfo.loadIcon(getActivity().getPackageManager());

- 39,067
- 29
- 104
- 160

- 6,422
- 2
- 52
- 60
-
I tried this but always the packageInfo is null. i'm missing any permissions? – 1HaKr Jun 11 '11 at 13:14
-
work for me at Samsung Galaxy Tab 8.9, Android version 3.2. packageInfo is NOT null, intent is null if app not yet installed. – giacatho Jul 05 '12 at 02:39
As you might have found out, PackageManager will only be useful to you if the app is installed.
To solve your problem of getting the information without installing the app use the APK extractor, see: http://code.google.com/p/apk-extractor/downloads/detail?name=APK-Extractor-src-1.0.zip&can=2&q=
This project is an attempt to develop a publicly available parser which can parse Android's binary XML. AAPT (Android Asset Packaging Tool) encodes/decodes XML resources in Google's own proprietary binary XML format. It's a common believe that this is a generic WBXML format and any WBXML capable parser can parse it. But this is not true.
If you are planning to explore Android's Binary XML, my code base can help you to start and build service on top of it.
Version 1.0- is capable of parsing Android Manifest, XML layouts etc. and converting DEX/ODEX to CLASS, which can be opened by any de-compiler.
his blog is here: http://prasanta-paul.blogspot.com/2012/03/android-apk-extractor.html

- 23,475
- 11
- 118
- 166