Java Code Examples for android.content.pm.PackageManager#getPackageArchiveInfo()
The following examples show how to use
android.content.pm.PackageManager#getPackageArchiveInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From ClassLoader with Apache License 2.0 | 6 votes |
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); return String.format(Locale.ENGLISH, "\n*** Apk info ***\nversionCode:%d\nversionName:%s\n*** Apk info ***\n", info.versionCode, info.versionName); } catch (Exception e) { e.printStackTrace(); return e.toString(); } }
Example 2
Source File: FileUtil.java From LiveGiftLayout with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: ApplicationManager.java From product-emm with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { long referenceId = intent.getLongExtra( DownloadManager.EXTRA_DOWNLOAD_ID, -1); if (downloadReference == referenceId) { String downloadDirectoryPath = Environment.getExternalStoragePublicDirectory(Environment. DIRECTORY_DOWNLOADS).getPath(); File file = new File(downloadDirectoryPath, downloadedAppName); if (file.exists()) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(downloadDirectoryPath + File.separator + downloadedAppName, PackageManager.GET_ACTIVITIES); Preference.putString(context, context.getResources().getString(R.string.shared_pref_installed_app), info.packageName); Preference.putString(context, context.getResources().getString(R.string.shared_pref_installed_file), downloadedAppName); startInstallerIntent(Uri.fromFile(new File(downloadDirectoryPath + File.separator + downloadedAppName))); } } }
Example 4
Source File: AppUpgradeService.java From AndroidBleManager with Apache License 2.0 | 6 votes |
public boolean checkApkFile(String apkFilePath) { boolean result = false; try{ PackageManager pManager = getPackageManager(); PackageInfo pInfo = pManager.getPackageArchiveInfo(apkFilePath, PackageManager.GET_ACTIVITIES); if (pInfo == null) { result = false; } else { result = true; } } catch(Exception e) { result = false; e.printStackTrace(); } return result; }
Example 5
Source File: AndroidUtils.java From Aria with Apache License 2.0 | 6 votes |
/** * 判断是否安装 */ public static boolean apkIsInstall(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 { pm.getPackageInfo(appInfo.packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true; } catch (PackageManager.NameNotFoundException localNameNotFoundException) { return false; } } return false; }
Example 6
Source File: IconUtils.java From FireFiles with Apache License 2.0 | 6 votes |
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; }
Example 7
Source File: VenvyFileUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
/** * 获取APK名称 * * @param context * @param apkPath * @return */ public static String getApkLabel(Context context, String apkPath) { PackageManager packageManager = context.getPackageManager(); PackageInfo pi = packageManager.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if (pi != null) { ApplicationInfo appInfo = pi.applicationInfo; appInfo.sourceDir = apkPath; appInfo.publicSourceDir = apkPath; try { return appInfo.loadLabel(packageManager).toString(); } catch (Exception e) { e.printStackTrace(); } } return ""; }
Example 8
Source File: Thumbnail.java From UMS-Interface with GNU General Public License v3.0 | 6 votes |
/** * get the drawable from the path of the apk <br/> * 采用了新的办法获取APK图标,之前的失败是因为android中存在的一个BUG,通过 * appInfo.publicSourceDir = apkPath;来修正这个问题,详情参见: * http://code.google.com/p/android/issues/detail?id=9151 **/ 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("ApkIconLoader", e.toString()); } } return null; }
Example 9
Source File: Tools.java From isu with GNU General Public License v3.0 | 6 votes |
public static boolean NeedUpdate(Context context) { if (isuInstalled(context)) { boolean su = SuBinary(); String sdcard = Environment.getExternalStorageDirectory().getPath(); String temp_app = sdcard + "/temp.apk"; String app_folder = "" + runCommand("pm path " + context.getPackageName() + " | head -n1 | cut -d: -f2", su, context); String[] OriginaliSuApk = app_folder.split("com"); runCommand("cp -f " + OriginaliSuApk[0] + "com.bhb27.isu*/base.apk /" + temp_app, su, context); double this_versionApp = Float.valueOf(BuildConfig.VERSION_NAME); double versionApp = 0; if (NewexistFile(temp_app, true, context)) { try { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(temp_app, 0); versionApp = Float.valueOf(info.versionName); } catch (NullPointerException ignored) {} } else versionApp = Float.valueOf(BuildConfig.VERSION_NAME); runCommand("rm -rf /" + temp_app, su, context); if (versionApp > this_versionApp) return true; if (versionApp <= this_versionApp) return false; } return false; }
Example 10
Source File: AppInfoUtils.java From Bailan with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: ApkUtil.java From file-downloader with Apache License 2.0 | 5 votes |
/** * get UnInstallApkPackageName * * @param context Context * @param apkPath apkPath * @return apk PackageName */ public static String getUnInstallApkPackageName(Context context, String apkPath) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; if (appInfo != null) { return appInfo.packageName; } } return null; }
Example 12
Source File: APKImageLoader.java From Kernel-Tuner with GNU General Public License v3.0 | 5 votes |
@Override protected Drawable loadCacheItem(ImageData imageData) { PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageArchiveInfo(imageData.path, 0); pi.applicationInfo.sourceDir = imageData.path; pi.applicationInfo.publicSourceDir = imageData.path; return pi.applicationInfo.loadIcon(pm); }
Example 13
Source File: ApkUpdateUtils.java From BaseProject with Apache License 2.0 | 5 votes |
/** * 获取下载的apk信息 * @param context * @param path * @return */ private static PackageInfo getApkInfo(Context context, String path) { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES); if (null != info) { return info; } return null; }
Example 14
Source File: AdhellDownloadBroadcastReceiver.java From notSABS with MIT License | 4 votes |
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "onReceive download completed"); long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); SharedPreferences sharedPref = App.get().getApplicationContext() .getSharedPreferences(context.getString(R.string.download_manager_sharedPrefs), Context.MODE_PRIVATE); long savedReferenceId = sharedPref.getLong(context.getString(R.string.download_manager_reference_id), -2); if (referenceId == savedReferenceId) { DeviceAdminInteractor deviceAdminInteractor = DeviceAdminInteractor.getInstance(); if (deviceAdminInteractor.isKnoxEnabled()) { Log.i(TAG, "Knox enabled"); File fileDir = context.getExternalFilesDir(null); if (fileDir == null || !fileDir.exists()) { return; } String downloadDir = fileDir.toString(); Log.i(TAG, "getAll dit: " + downloadDir); String apkFilePath = downloadDir + "/adhell.apk"; File apkFile = new File(apkFilePath); if (!apkFile.exists()) { Log.w(TAG, ".apk file does not exist"); return; } final PackageManager pm = mContext.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkFilePath, 0); Toast.makeText(mContext, "VersionCode : " + info.versionCode + ", VersionName : " + info.versionName, Toast.LENGTH_LONG).show(); if (info.versionCode == BuildConfig.VERSION_CODE && info.versionName.equals(BuildConfig.VERSION_NAME)) { Log.w(TAG, "Same version .apk. Aborted"); return; } boolean isInstalled = deviceAdminInteractor.installApk(apkFilePath); Log.i(TAG, "Path to: " + apkFilePath); if (isInstalled) { Toast.makeText(context, "Adhell app updated!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(context, "Failed to update Adhell.", Toast.LENGTH_LONG).show(); } } else { Log.w(TAG, "Knox is disabled"); } } }
Example 15
Source File: ImportItem.java From apkextractor with GNU General Public License v3.0 | 4 votes |
public ImportItem(@NonNull Context context,@NonNull FileItem fileItem){ this.fileItem=fileItem; this.context=context; version_name=context.getResources().getString(R.string.word_unknown); version_code=context.getResources().getString(R.string.word_unknown); minSdkVersion=context.getResources().getString(R.string.word_unknown); targetSdkVersion=context.getResources().getString(R.string.word_unknown); drawable=context.getResources().getDrawable(R.drawable.icon_file); if(fileItem.getName().trim().toLowerCase().endsWith(".zip") ||fileItem.getName().trim().toLowerCase().endsWith(SPUtil.getCompressingExtensionName(context).toLowerCase())){ importType=ImportType.ZIP; drawable=context.getResources().getDrawable(R.drawable.icon_zip); } if(fileItem.getName().trim().toLowerCase().endsWith(".xapk")){ importType=ImportType.ZIP; drawable=context.getResources().getDrawable(R.drawable.icon_xapk); } if(fileItem.getName().trim().toLowerCase().endsWith(".apk")){ importType=ImportType.APK; PackageManager packageManager=context.getApplicationContext().getPackageManager(); if(fileItem.isFileInstance()){ try{ int flag=0; final SharedPreferences settings=SPUtil.getGlobalSharedPreferences(context); if(settings.getBoolean(Constants.PREFERENCE_LOAD_PERMISSIONS,Constants.PREFERENCE_LOAD_PERMISSIONS_DEFAULT))flag|=PackageManager.GET_PERMISSIONS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_ACTIVITIES,Constants.PREFERENCE_LOAD_ACTIVITIES_DEFAULT))flag|=PackageManager.GET_ACTIVITIES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_RECEIVERS,Constants.PREFERENCE_LOAD_RECEIVERS_DEFAULT))flag|=PackageManager.GET_RECEIVERS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_APK_SIGNATURE,Constants.PREFERENCE_LOAD_APK_SIGNATURE_DEFAULT))flag|=PackageManager.GET_SIGNATURES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_SERVICES,Constants.PREFERENCE_LOAD_SERVICES_DEFAULT))flag|=PackageManager.GET_SERVICES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PROVIDERS,Constants.PREFERENCE_LOAD_PROVIDERS_DEFAULT))flag|=PackageManager.GET_PROVIDERS; packageInfo=packageManager.getPackageArchiveInfo(fileItem.getPath(),flag); }catch (Exception e){e.printStackTrace();} if(packageInfo!=null){ packageInfo.applicationInfo.sourceDir=fileItem.getPath(); packageInfo.applicationInfo.publicSourceDir=fileItem.getPath(); drawable=packageInfo.applicationInfo.loadIcon(packageManager); version_name=packageInfo.versionName; version_code=String.valueOf(packageInfo.versionCode); if(Build.VERSION.SDK_INT>23){ minSdkVersion=String.valueOf(packageInfo.applicationInfo.minSdkVersion); } targetSdkVersion=String.valueOf(packageInfo.applicationInfo.targetSdkVersion); }else{ drawable=context.getResources().getDrawable(R.drawable.icon_apk); } }else{ drawable=context.getResources().getDrawable(R.drawable.icon_apk); } } length=fileItem.length(); lastModified =fileItem.lastModified(); }
Example 16
Source File: AndroidUtils.java From Aria with Apache License 2.0 | 4 votes |
/** * 获取未安装软件包的包名 */ public static PackageInfo getApkPackageInfo(Context context, String apkPath) { PackageManager pm = context.getPackageManager(); return pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); }
Example 17
Source File: MoreAty.java From Huochexing12306 with Apache License 2.0 | 4 votes |
/** * 取得安装包文件 * @return 获取失败则返回null */ private File getAPKFile() { File targetFile = null; String versionName = null; PackageManager pm = getPackageManager(); String strUmengAPKDownloadDir = Environment.getExternalStorageDirectory()+"/Download/.um/apk"; File file = new File(strUmengAPKDownloadDir); if (file.exists() && file.isDirectory()){ File[] subFiles = file.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(".apk")){ return true; }else{ return false; } } }); if (subFiles != null){ int maxVersionCode = 0; for(File f:subFiles){ PackageInfo pInfo = pm.getPackageArchiveInfo(f.getAbsolutePath(), PackageManager.GET_ACTIVITIES); if (pInfo != null){ String strPName = pInfo.applicationInfo.packageName; //可能存在多个离线安装包的情况,所以有寻找最新版 if (strPName.equals(getApplicationInfo().packageName) && (pInfo.versionCode>maxVersionCode)){ targetFile = f; versionName = pInfo.versionName; } } } } } if (targetFile != null){ //重命名文件 File newFile = new File(targetFile.getParent() + "/huochexing"+(versionName==null?"":("_"+versionName)) + ".apk"); targetFile.renameTo(newFile); } return targetFile; }
Example 18
Source File: Util.java From XKik with GNU General Public License v3.0 | 4 votes |
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; }
Example 19
Source File: SkinManager.java From injor with Apache License 2.0 | 2 votes |
/** * 获取外部apk的包名 * * @param skinPluginPath * @return */ private PackageInfo getPackageInfo(String skinPluginPath) { PackageManager pm = mContext.getPackageManager(); return pm.getPackageArchiveInfo(skinPluginPath, PackageManager.GET_ACTIVITIES); }
Example 20
Source File: SkinCompatManager.java From Android-skin-support with MIT License | 2 votes |
/** * 获取皮肤包包名. * * @param skinPkgPath sdcard中皮肤包路径. * @return */ public String getSkinPackageName(String skinPkgPath) { PackageManager mPm = mAppContext.getPackageManager(); PackageInfo info = mPm.getPackageArchiveInfo(skinPkgPath, PackageManager.GET_ACTIVITIES); return info.packageName; }