FileDocCategorySizeDatePackage
PackageUtil.javaAPI DocAndroid 1.5 API4834Wed May 06 22:42:46 BST 2009com.android.packageinstaller

PackageUtil

public class PackageUtil extends Object
This is a utility class for defining some utility methods and constants used in the package installer application.

Fields Summary
public static final String
PREFIX
public static final String
INTENT_ATTR_INSTALL_STATUS
public static final String
INTENT_ATTR_APPLICATION_INFO
public static final String
INTENT_ATTR_PERMISSIONS_LIST
public static final String
INTENT_ATTR_PACKAGE_NAME
Constructors Summary
Methods Summary
public static android.graphics.drawable.DrawablegetApplicationIcon(android.content.Context context, android.content.pm.ApplicationInfo appInfo)

        return appInfo.loadIcon(context.getPackageManager());
    
public static android.content.pm.ApplicationInfogetApplicationInfo(android.net.Uri packageURI)

    
    /*
     * Utility method to get application information for a given packageURI
     */
          
        final String archiveFilePath = packageURI.getPath();
        PackageParser packageParser = new PackageParser(archiveFilePath);
        File sourceFile = new File(archiveFilePath);
        DisplayMetrics metrics = new DisplayMetrics();
        metrics.setToDefaults();
        PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
        if (pkg == null) {
            return null;
        }
        return pkg.applicationInfo;
    
public static java.lang.CharSequencegetApplicationLabel(android.content.Context context, android.content.pm.ApplicationInfo appInfo)

        CharSequence appName = appInfo.loadLabel(context.getPackageManager());
        if(appName == null) {
            appName = context.getString(R.string.unknown);
        }
        return appName;
    
public static PackageParser.PackagegetPackageInfo(android.net.Uri packageURI)

        final String archiveFilePath = packageURI.getPath();
        PackageParser packageParser = new PackageParser(archiveFilePath);
        File sourceFile = new File(archiveFilePath);
        DisplayMetrics metrics = new DisplayMetrics();
        metrics.setToDefaults();
        return packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
    
public static android.view.ViewinitAppSnippet(android.app.Activity context, android.content.pm.ApplicationInfo appInfo, int snippetId)

        
        View appSnippet = context.findViewById(snippetId);        
        ((ImageView)appSnippet.findViewById(R.id.app_icon)).setImageDrawable(
                getApplicationIcon(context, appInfo));
        ((TextView)appSnippet.findViewById(R.id.app_name)).setText(
                getApplicationLabel(context, appInfo));
        return appSnippet;
    
public static booleanisPackageAlreadyInstalled(android.app.Activity context, java.lang.String pkgName)

        List<PackageInfo> installedList = context.getPackageManager().getInstalledPackages(
                PackageManager.GET_UNINSTALLED_PACKAGES);
        int installedListSize = installedList.size();
        for(int i = 0; i < installedListSize; i++) {
            PackageInfo tmp = installedList.get(i);
            if(pkgName.equalsIgnoreCase(tmp.packageName)) {
                return true;
            }
            
        }
        return false;