本文整理汇总了Java中android.content.pm.PackageManager.getApplicationIcon方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getApplicationIcon方法的具体用法?Java PackageManager.getApplicationIcon怎么用?Java PackageManager.getApplicationIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getApplicationIcon方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAppIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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);
}
示例2: loadPackagePathIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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;
}
示例3: doInBackground
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@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];
}
示例4: doInBackground
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@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;
}
示例5: getInstalledApps
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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;
}
示例6: getPackageIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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);
}
示例7: getUninstalledApkIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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);
}
示例8: ApkItem
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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;
}