当前位置: 首页>>代码示例>>Java>>正文


Java PackageManager.getApplicationIcon方法代码示例

本文整理汇总了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);
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:15,代码来源:AppInfoUtils.java

示例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;
 }
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:20,代码来源:IconUtils.java

示例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];
}
 
开发者ID:matejdro,项目名称:WearVibrationCenter,代码行数:24,代码来源:AppPickerFragment.java

示例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;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:18,代码来源:AppsIconTask.java

示例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;
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:18,代码来源:CreateCredentialActivity.java

示例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);
}
 
开发者ID:zhaobao,项目名称:AppsTimeline,代码行数:10,代码来源:AppUtil.java

示例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);
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:14,代码来源:ApkUtils.java

示例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;
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:13,代码来源:ApkItem.java


注:本文中的android.content.pm.PackageManager.getApplicationIcon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。