Java Code Examples for android.content.pm.PackageManager.getApplicationIcon()

The following are Jave code examples for showing how to use getApplicationIcon() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Bailan   File: AppInfoUtils.java   View Source Code Vote up 6 votes
public static Drawable getAppIcon(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = getPackageInfo(context, apkFilepath);
    if (pkgInfo == null) {
        return null;
    }

    ApplicationInfo appInfo = pkgInfo.applicationInfo;
    if (Build.VERSION.SDK_INT >= 8) {
        appInfo.sourceDir = apkFilepath;
        appInfo.publicSourceDir = apkFilepath;
    }
    return pm.getApplicationIcon(appInfo);
}
 
Example 2
Project: easyfilemanager   File: IconUtils.java   View Source Code Vote up 6 votes
public static Drawable loadPackagePathIcon(Context context, String path, String mimeType){
 	int icon =  sMimeIcons.get(mimeType);
     if (path != null) {
         final PackageManager pm = context.getPackageManager();
try {
	final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
	if (packageInfo != null) {
		packageInfo.applicationInfo.sourceDir = packageInfo.applicationInfo.publicSourceDir = path;
		// know issue with nine patch image instead of drawable
		return pm.getApplicationIcon(packageInfo.applicationInfo);
	}
} catch (Exception e) {
	return ContextCompat.getDrawable(context, icon);
}
     } else {
         return ContextCompat.getDrawable(context, icon);
     }
     return null;
 }
 
Example 3
Project: WearVibrationCenter   File: AppPickerFragment.java   View Source Code Vote up 6 votes
@Override
protected Integer doInBackground(Object... params) {
    if (getActivity() == null) {
        return null;
    }

    final PackageManager pm = getActivity().getPackageManager();

    try {
        Drawable icon = pm.getApplicationIcon((String) params[0]);
        if (!(icon instanceof BitmapDrawable)) {
            icon = ResourcesCompat.getDrawable(getResources(), android.R.drawable.sym_def_app_icon, null);
        }

        Bitmap iconBitmap = BitmapUtils.getBitmap(icon);
        if (iconBitmap != null) {
            iconCache.put((String) params[0], iconBitmap);
        }
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    return (Integer) params[1];
}
 
Example 4
Project: Brevent   File: AppsIconTask.java   View Source Code Vote up 6 votes
@Override
protected AppsItemViewHolder doInBackground(Object... params) {
    PackageManager packageManager = (PackageManager) params[0];
    AppsItemViewHolder holder = (AppsItemViewHolder) params[1];
    try {
        Intent launchIntent = packageManager.getLaunchIntentForPackage(holder.packageName);
        if (launchIntent == null) {
            holder.icon = packageManager.getApplicationIcon(holder.packageName);
        } else {
            holder.icon = packageManager.resolveActivity(launchIntent, 0).activityInfo
                    .loadIcon(packageManager);
        }
    } catch (PackageManager.NameNotFoundException e) { // NOSONAR
        // do nothing
    }
    return holder;
}
 
Example 5
Project: OpenYOLO-Android   File: CreateCredentialActivity.java   View Source Code Vote up 6 votes
private List<App> getInstalledApps() {
    List<String> appPackageNames = InstalledAppsUtil.getInstalledAppsList(this);
    ArrayList<App> apps = new ArrayList<>();
    PackageManager pm = getPackageManager();
    for (String packageName : appPackageNames) {
        try {
            ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
            String appName = pm.getApplicationLabel(info).toString();
            Drawable appIcon = pm.getApplicationIcon(info);
            apps.add(new App(packageName, appName, appIcon));
        } catch (PackageManager.NameNotFoundException e) {
            // skip this app
        }
    }

    return apps;
}
 
Example 6
Project: FireFiles   File: IconUtils.java   View Source Code Vote up 6 votes
public static Drawable loadPackagePathIcon(Context context, String path, String mimeType){
 	int icon =  sMimeIcons.get(mimeType);
     if (path != null) {
         final PackageManager pm = context.getPackageManager();
try {
	final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
	if (packageInfo != null) {
		packageInfo.applicationInfo.sourceDir = packageInfo.applicationInfo.publicSourceDir = path;
		// know issue with nine patch image instead of drawable
		return pm.getApplicationIcon(packageInfo.applicationInfo);
	}
} catch (Exception e) {
	return ContextCompat.getDrawable(context, icon);
}
     } else {
         return ContextCompat.getDrawable(context, icon);
     }
     return null;
 }
 
Example 7
Project: simple-share-android   File: IconUtils.java   View Source Code Vote up 6 votes
public static Drawable loadPackagePathIcon(Context context, String path, String mimeType){
 	int icon =  sMimeIcons.get(mimeType);
     if (path != null) {
         final PackageManager pm = context.getPackageManager();
try {
	final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
	if (packageInfo != null) {
		packageInfo.applicationInfo.sourceDir = packageInfo.applicationInfo.publicSourceDir = path;
		// know issue with nine patch image instead of drawable
		return pm.getApplicationIcon(packageInfo.applicationInfo);
	}
} catch (Exception e) {
	return ContextCompat.getDrawable(context, icon);
}
     } else {
         return ContextCompat.getDrawable(context, icon);
     }
     return null;
 }
 
Example 8
Project: AppsTimeline   File: AppUtil.java   View Source Code Vote up 5 votes
public static Drawable getPackageIcon(Context context, String packageName) {
    PackageManager manager = context.getPackageManager();
    try {
        return manager.getApplicationIcon(packageName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return context.getResources().getDrawable(R.drawable.ic_default_app);
}
 
Example 9
Project: jackknife   File: ApkUtils.java   View Source Code Vote up 5 votes
public static Drawable getUninstalledApkIcon(Context context, String apkPath) {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packageInfo = getUninstalledApkPackageInfo(context, apkPath);
    if (packageInfo == null) {
        return null;
    }
    ApplicationInfo applicationInfo = packageInfo.applicationInfo;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        applicationInfo.sourceDir = apkPath;
        applicationInfo.publicSourceDir = apkPath;
    }
    return packageManager.getApplicationIcon(applicationInfo);
}
 
Example 10
Project: DroidPlugin   File: ApkItem.java   View Source Code Vote up 5 votes
ApkItem(PackageManager pm, PackageInfo info, String path) {
    try {
        icon = pm.getApplicationIcon(info.applicationInfo);
    } catch (Exception e) {
        icon = pm.getDefaultActivityIcon();
    }
    title = pm.getApplicationLabel(info.applicationInfo);
    versionName = info.versionName;
    versionCode = info.versionCode;
    apkfile = path;
    packageInfo = info;
}