df1e df1e - 4 months ago 22
Android Question

Android App Icon Filemanager

Hi in my Filemanager i want to add an Option to show the App Icons of a directory. I have tried this but it didnt work. What did I a wrong?

ImageView icon;
private static Activity activity;
String temp = mFileMang.getCurrentDir();

} else if (sub_ext.equalsIgnoreCase("apk")) {
final Drawable appicon;
try {
PackageInfo packageInfo = activity.getPackageManager()
.getPackageArchiveInfo(temp,
PackageManager.GET_ACTIVITIES);
ApplicationInfo appInfo = packageInfo.applicationInfo;

appInfo.sourceDir = temp;
appInfo.publicSourceDir = temp;

appicon = appInfo
.loadIcon(activity.getPackageManager());
mViewHolder.icon.setImageDrawable(appicon);

} catch (Exception e) {
mViewHolder.icon.setImageResource(R.drawable.appicon);
}

Answer

to add this http://stackoverflow.com/questions/17919151/android-app-icon-filemanager/17924795#17924795 to my code i need to cut it. finally i got this:

but when I open the directory it load only 1 icon and show it for all other apps too. https://www.dropbox.com/s/e2bonh3fkfseggf/Screenshot_2013-07-31-13-58-18.png

File file = new File(temp + "/" + mDataSource.get(position));

} else if (sub_ext.equalsIgnoreCase("apk")) {

    try {
        Drawable icon = getApk(file);
        mViewHolder.icon.setImageDrawable(icon);

    } catch (Exception e) {
        mViewHolder.icon.setImageResource(R.drawable.appicon);
    }


private Drawable getApk(File file2) {
    try {
        String path = mFileMang.getCurrentDir();
        File file = new File(path);
        String[] list = file.list();

        for (String str : list) {
            String not_installed_apk_file = path + "/" + str;
            PackageManager pm = mContext.getPackageManager();
            PackageInfo pi = pm.getPackageArchiveInfo(
                    not_installed_apk_file, 0);
            if (pi == null)
                continue;
            // the secret are these two lines....
            pi.applicationInfo.sourceDir = not_installed_apk_file;
            pi.applicationInfo.publicSourceDir = not_installed_apk_file;
            //
            res = pi.applicationInfo.loadIcon(pm);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return res;
}
Comments