Get apk file icon, version, name

后端 未结 5 909
粉色の甜心
粉色の甜心 2020-12-04 11:52

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条回答
  •  [愿得一人]
    2020-12-04 12:01

    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.

提交回复
热议问题