Example usage for android.content.pm PackageManager getPackageArchiveInfo

List of usage examples for android.content.pm PackageManager getPackageArchiveInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getPackageArchiveInfo.

Prototype

public PackageInfo getPackageArchiveInfo(String archiveFilePath, @PackageInfoFlags int flags) 

Source Link

Document

Retrieve overall information about an application package defined in a package archive file

Usage

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilepath, int flag) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = null;/*from w  ww. j  av  a2 s . co m*/
    try {
        pkgInfo = pm.getPackageArchiveInfo(apkFilepath, flag);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return pkgInfo;
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = null;//w w  w .ja v a2  s  . c  om
    try {
        pkgInfo = pm.getPackageArchiveInfo(apkFilepath, PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        // should be something wrong with parse
        e.printStackTrace();
    }

    return pkgInfo;
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilePath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo packageInfo = null;//from   w  w  w. ja v  a2 s. c o  m
    try {
        packageInfo = pm.getPackageArchiveInfo(apkFilePath,
                PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packageInfo;
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = null;//from  www .  j  a v a 2 s  .  c om
    try {
        pkgInfo = pm.getPackageArchiveInfo(apkFilepath,
                PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
    } catch (Exception e) {
        // should be something wrong with parse
        e.printStackTrace();
    }

    return pkgInfo;
}

From source file:Main.java

@Nullable
public static Bitmap extractApkIcon(@NonNull final PackageManager pm, @NonNull final File file) {
    final String filePath = file.getPath();
    final PackageInfo packageInfo = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
    if (packageInfo != null) {
        final ApplicationInfo appInfo = packageInfo.applicationInfo;
        if (appInfo != null) {
            appInfo.sourceDir = filePath;
            appInfo.publicSourceDir = filePath;
            final Drawable icon = appInfo.loadIcon(pm);
            if (icon != null) {
                return ((BitmapDrawable) icon).getBitmap();
            }//from  w w  w  .ja  v a  2s .  c o  m
        }
    }
    return null;
}

From source file:com.example.util.Utils.java

public static HashMap<String, Object> getApkInfo(Context context, File file) {
    PackageManager pm = context.getPackageManager();
    String filePath = file.getAbsolutePath();
    PackageInfo info = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
    if (info == null) {
        return null;
    }//from  w w  w .ja  v  a  2s  .  c  om
    ApplicationInfo appInfo = info.applicationInfo;
    info.applicationInfo.sourceDir = filePath;
    info.applicationInfo.publicSourceDir = filePath;
    Drawable icon = pm.getApplicationIcon(appInfo);

    HashMap<String, Object> apk = new HashMap<String, Object>();
    apk.put(Constants.KEY_PRODUCT_ICON, icon);
    apk.put(Constants.KEY_PRODUCT_NAME, file.getName());
    apk.put(Constants.KEY_PRODUCT_INFO, filePath);
    apk.put(Constants.KEY_PRODUCT_DESCRIPTION, file.getAbsolutePath());
    apk.put(Constants.KEY_PRODUCT_PAY_TYPE, Constants.PAY_TYPE_FREE);
    apk.put(Constants.KEY_PLACEHOLDER, false);
    return apk;
}

From source file:com.amaze.carbonfilemanager.ui.icons.IconHolder.java

private Bitmap getAppDrawable(String path) throws OutOfMemoryError {
    Bitmap bitsat;//w  ww . j a v  a2s  .  c o m
    try {
        PackageManager pm = mContext.getPackageManager();
        PackageInfo pi = pm.getPackageArchiveInfo(path, 0);
        // // the secret are these two lines....
        pi.applicationInfo.sourceDir = path;
        pi.applicationInfo.publicSourceDir = path;
        // //
        Drawable d = pi.applicationInfo.loadIcon(pm);

        Bitmap d1 = null;
        d1 = ((BitmapDrawable) d).getBitmap();
        bitsat = d1;
    } catch (Exception e) {
        Drawable apk = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_apk_grid);
        Bitmap apk1 = ((BitmapDrawable) apk).getBitmap();
        bitsat = apk1;
    }
    return bitsat;
}