當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。