本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}