if(file.getPath().endsWith(".apk")){
       
String filePath = file.getPath();
       
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(filePath,PackageManager.GET_ACTIVITIES);
       
if(packageInfo !=null){
           
ApplicationInfo appInfo = packageInfo.applicationInfo;
           
if(Build.VERSION.SDK_INT >=8){
                appInfo
.sourceDir = filePath;
                appInfo
.publicSourceDir = filePath;
           
}
           
Drawable icon = appInfo.loadIcon(context.getPackageManager());
            bmpIcon
=((BitmapDrawable) icon).getBitmap();
       
}
   
}

The most important line is appInfo.publicSourceDir = filePath;

This is a bug. See http://code.google.com/p/android/issues/detail?id=9151

The null check packageInfo != null is there in case the .apk is not parsed correctly.

 

 

 

 

FROM:

http://stackoverflow.com/questions/5674683/how-to-show-icon-of-apk-in-my-file-manager

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()