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


Java PackageManager.getPackageArchiveInfo方法代码示例

本文整理汇总了Java中android.content.pm.PackageManager.getPackageArchiveInfo方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getPackageArchiveInfo方法的具体用法?Java PackageManager.getPackageArchiveInfo怎么用?Java PackageManager.getPackageArchiveInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.pm.PackageManager的用法示例。


在下文中一共展示了PackageManager.getPackageArchiveInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: getLocalApkIcon

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static Bitmap getLocalApkIcon(PackageManager pm, String apkPath) {
    Drawable icon;
    Bitmap iconBmp;
    try {
        PackageInfo pi = pm.getPackageArchiveInfo(apkPath,
                PackageManager.GET_ACTIVITIES);
        pi.applicationInfo.sourceDir = apkPath;
        pi.applicationInfo.publicSourceDir = apkPath;
        icon = pi.applicationInfo.loadIcon(pm);
        iconBmp = drawableToBitmap(icon);
    } catch (Exception e) {
        return null;
    }

    return iconBmp;
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:17,代码来源:FeThumbUtils.java

示例3: getApkIconThumbnail

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * from apk file get apk icon bitmap.
 * @param context
 * @param apkPath
 * @return
 */
public static Bitmap getApkIconThumbnail(Context context, String apkPath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkPath,
            PackageManager.GET_ACTIVITIES);
    Drawable drawable = null;
    if (info != null) {
        ApplicationInfo appInfo = info.applicationInfo;
        appInfo.sourceDir = apkPath;
        appInfo.publicSourceDir = apkPath;
        try {
            drawable = appInfo.loadIcon(pm);
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }
    }
    if(drawable!=null){
        return drawableToBitmap(drawable);
    }
    return null;
}
 
开发者ID:jiajunhui,项目名称:XDisplay,代码行数:27,代码来源:Util.java

示例4: getApkPackageName

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static String getApkPackageName(Context context,String apkPath) {
    try {
        if(context==null)
            return null;
        PackageManager pm = context.getPackageManager();
        if(SkinStringUtils.isNull(apkPath)){
            pm = context.getPackageManager();
        }
        PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
        ApplicationInfo appInfo = null;
        if (info != null) {
            appInfo = info.applicationInfo;
            String packageName = appInfo.packageName;
            return packageName;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:MeetYouDevs,项目名称:Android-Skin,代码行数:21,代码来源:PackageUtil.java

示例5: getApkInfo

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public String getApkInfo(String fileName) {
    try {
        String dexPath = null;
        if (getExternalFilesDir(null) != null) {
            dexPath = new File(getExternalFilesDir(null), fileName).getAbsolutePath();
        } else if (getFilesDir() != null) {
            dexPath = new File(getFilesDir(), fileName).getAbsolutePath();
        }

        PackageManager pm = getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(dexPath, 0);

        StringBuilder sb = new StringBuilder();
        sb.append("\n*** Apk info ***\n");
        sb.append("versionCode:" + info.versionCode);
        sb.append("\nversionName:" + info.versionName);
        sb.append("\n*** Apk info ***\n");

        return sb.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return e.toString();
    }
}
 
开发者ID:Catherine22,项目名称:ClassLoader,代码行数:25,代码来源:OpenResourceActivity.java

示例6: parserApkOrmModel

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * parserApkOrmModel
 *
 * @param context context
 * @param apkPath apkPath
 * @return model
 */
public static ApkOrmModel parserApkOrmModel(Context context, String apkPath) {
    File file = new File(apkPath);
    if (file.exists() && apkPath.endsWith(".apk")) {
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pkg = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
            if (pkg != null) {
                ApkOrmModel model = new ApkOrmModel();
                model.setApkPath(apkPath);
                model.setApkPackageName(pkg.packageName);
                model.setApkVersionCode(pkg.versionCode);
                model.setApkVersionName(pkg.versionName);
                model.setApkSignture(ApkSignture.getSignture(context, apkPath));
                model.setApkSha1(ApkMd5.sha1(file));
                return model;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:30,代码来源:ApkLoader.java

示例7: getApkIcon

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static Drawable getApkIcon(Context context, String apkPath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkPath,
            PackageManager.GET_ACTIVITIES);
    if (info != null) {
        ApplicationInfo appInfo = info.applicationInfo;
        appInfo.sourceDir = apkPath;
        appInfo.publicSourceDir = apkPath;
        try {
            return appInfo.loadIcon(pm);
        } catch (OutOfMemoryError e) {
            Log.e(LOG_TAG, e.toString());
        }
    }
    return null;
}
 
开发者ID:DyncKathline,项目名称:LiveGiftLayout,代码行数:17,代码来源:FileUtil.java

示例8: getPackageName

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/** 根据文件路径获取包名 */
public static String getPackageName(Context context, String filePath) {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo info = packageManager.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
    if (info != null) {
        ApplicationInfo appInfo = info.applicationInfo;
        return appInfo.packageName;  //得到安装包名称
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:ApkUtils.java

示例9: getPackageInfo

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = null;
    try {
        pkgInfo = pm.getPackageArchiveInfo(apkFilepath, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
    } catch (Exception e) {
        // should be something wrong with parse
        e.printStackTrace();
    }
    return pkgInfo;
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:12,代码来源:AppInfoUtils.java

示例10: checkApk

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@CheckResult
public static boolean checkApk(Context context, @NonNull String apkPath) {
    try {
        PackageManager pm = context.getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
        if (info != null) {
            return true;
        }
    } catch (Exception e) {
        Toast.makeText(context, "安装包失效", Toast.LENGTH_SHORT).show();
    }
    return false;
}
 
开发者ID:jiajieshen,项目名称:AndroidDevSamples,代码行数:14,代码来源:ApplicationUtil.java

示例11: getApkVersionCode

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static String getApkVersionCode(Context context, String filePath) {
	PackageManager pm = context.getPackageManager();
	PackageInfo info = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
	if (info != null) {
		return String.valueOf(info.versionCode);       //得到版本信息
	}
	return null;
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:9,代码来源:CommonUtils.java

示例12: getPackageArchiveInfo

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * 获取PackageInfo对象
 * 该方法解决了Android 2.x环境不能获取签名的系统问题,故可以“全面使用”
 */
public static PackageInfo getPackageArchiveInfo(PackageManager pm, String pkgFilePath, int flags) {
    PackageInfo info = null;
    try {
        info = pm.getPackageArchiveInfo(pkgFilePath, flags);
    } catch (Throwable e) {
        if (LogDebug.LOG) {
            e.printStackTrace();
        }
    }

    if (info == null) {
        return null;
    }

    // Android 2.x的系统通过常规手段(pm.getPackageArchiveInfo)时会返回null,只能通过底层实现
    // 判断依据:1、想要签名;2、没拿到签名;3、Android 4.0以前
    if ((flags & PackageManager.GET_SIGNATURES) != 0) {
        if (info.signatures == null) {
            if (Build.VERSION.SDK_INT < 14) {
                info.signatures = getPackageArchiveSignaturesInfoAndroid2x(pkgFilePath);
            }
        }
    }

    return info;
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:31,代码来源:PackageUtils.java

示例13: getKikVersion

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static String getKikVersion(XC_LoadPackage.LoadPackageParam lpparam, PackageManager pm) {
    String apkName = lpparam.appInfo.sourceDir;
    String fullPath = Environment.getExternalStorageDirectory() + "/" + apkName;
    PackageInfo info = pm.getPackageArchiveInfo(fullPath, 0);
    return info.versionName;
}
 
开发者ID:xkik-dev,项目名称:XKik,代码行数:7,代码来源:Util.java

示例14: getPackageInfo

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static PackageInfo getPackageInfo(Context context, String apkPath) {

        PackageManager packageManager = context.getPackageManager();

        PackageInfo packageInfo = packageInfoMap.get(apkPath);
        if (packageInfo == null) {

            packageInfo = packageManager.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);

            packageInfoMap.put(apkPath, packageInfo);

        }


        return packageInfo;

    }
 
开发者ID:XaskYSab,项目名称:CSkin,代码行数:18,代码来源:SPluginUtil.java

示例15: loadApk

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * loadApk
 *
 * @param context context
 * @param apkPath apkPath
 * @return
 */
public static ApkLoaded loadApk(Context context, String apkPath) {
    File file = new File(apkPath);
    if (file.exists() && apkPath.endsWith(".apk")) {
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pkg = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
            if (pkg != null) {
                if (mConstructor == null) {
                    mConstructor = ApkLoaded.class.getDeclaredConstructor();
                }
                mConstructor.setAccessible(true);
                ApkLoaded loaded = mConstructor.newInstance();
                loaded.setHostContext(context.getApplicationContext());
                ApplicationInfo info = pkg.applicationInfo;
                if (Build.VERSION.SDK_INT >= 8) {
                    info.sourceDir = apkPath;
                    info.publicSourceDir = apkPath;
                }
                info.nativeLibraryDir = ApkNative.copyNativeLibrary(apkPath);
                String applicationName = ApkManifestParser.getApplicationName(apkPath);
                if (applicationName != null && !"".equals(applicationName)) {
                    applicationName = parserClassName(pkg.packageName, applicationName);
                    info.className = applicationName;
                }
                loaded.setApkPath(apkPath);
                loaded.setApkName(pm.getApplicationLabel(info).toString());
                loaded.setApkIcon(info.loadIcon(pm));
                loaded.setApkSignture(ApkSignture.getSignture(context, apkPath));
                loaded.setApkSha1(ApkMd5.sha1(file));
                loaded.setApkInfo(pkg);
                loaded.setApkVersionCode(pkg.versionCode);
                loaded.setApkVersionName(pkg.versionName);
                loaded.setApkPackageManager(pm);
                loaded.setConfigures(ApkConfigure.getConfigure(ApkResources.getAssets(context, apkPath)));
                loaded.setFilters(ApkManifestParser.getIntentFilter(apkPath));
                loaded.setApkLauncher(getMainActivityName(loaded, info.packageName));
                loaded.setPermissions(parserPermissions(context, apkPath));
                loaded.setProviders(parseProviders(apkPath));
                ApkReceiver.unregisterReceiver(loaded);
                loaded.setApkApplication(createApplication(context, loaded, applicationName));
                ApkReceiver.registerReceiver(context, loaded);
                ApkLogger.get().debug("Load apk success :" + loaded, null);
                return loaded;
            } else {
                ApkLogger.get().debug("Load apk fail : package info is null", null);
            }
        } catch (Exception e) {
            ApkLogger.get().debug("Load apk fail", e);
        }
    } else {
        ApkLogger.get().debug("Invalid apk file : " + apkPath, null);
    }
    return null;
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:62,代码来源:ApkLoader.java


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