mediatek/packages/apps/FileManager/src/com/mediatek/filemanager/IconManager.java
文件中添加如下方法
//get
the icon of the file
public Drawable
getFileIcon1(FileInfo fileInfo) {
String mAPKFilePath="";
File
apkFile=fileInfo.getFile();
mAPKFilePath=apkFile.getPath();
if(mContext==null){
return
null;
}
mPm=mContext.getPackageManager();
PackageInfo info =
mPm.getPackageArchiveInfo(mAPKFilePath,
PackageManager.GET_ACTIVITIES);
if (info != null)
{
ApplicationInfo appInfo =
info.applicationInfo;
appInfo.sourceDir =
mAPKFilePath;
appInfo.publicSourceDir =
mAPKFilePath;
try
{
return
appInfo.loadIcon(mPm);
} catch (OutOfMemoryError e)
{
System.out.println("Fail loadIcon :
" +
e);
}
}
return
null;
}
在getIcon(**)方法中添加如下语句:
if(!fileInfo.isDirectory()){
String
filename=fileInfo.getFileName();
if(filename.endsWith(".apk")){
Drawable
apkIcon=getFileIcon1(fileInfo);
if(apkIcon!=null){
Bitmap.Config
config=apkIcon.getOpacity()!=PixelFormat.OPAQUE?Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565;
//将Drawable转变为Bitmap
Bitmap
bitmap=Bitmap.createBitmap(48,48,
config);
Canvas canvas=new Canvas(bitmap);
apkIcon.setBounds(0, 0, 48,
48);
apkIcon.draw(canvas);
icon= bitmap;
}
}
}
fileInfo.isDirectory() //判断文件是否是目录
文件管理器浏览APK显示其缩略图,布布扣,bubuko.com