Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get apk file icon, version, name

Tags:

android

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)

like image 767
POMATu Avatar asked Apr 14 '11 09:04

POMATu


1 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.

like image 68
Tam Avatar answered Oct 18 '22 20:10

Tam