This article describes the method of Android implementing the PackageManager to obtain all installer information. Share it for your reference, as follows:
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);//Get the package name of the installerfor (int i = 0; i < (); i++) { PackageInfo p = (i);//A package information //Print: good version, version name, package name... ("", "-------" + + "-------" + + "--------" + + "-------" + ); }
versionCode, versionName value source file
<manifest xmlns:andro package="" android:versionCode="2" // android:versionName="Version1" // >
Get the versionCode of the current application, versionName
int versionCode = 0; try { versionCode = getPackageManager().getPackageInfo((), 0).versionCode; } catch (NameNotFoundException e) { (); }
Code:
// Check the package name to determine whether the APK is installedprivate boolean checkPackageExist(boolean getSysPackages) { boolean packageExist = false; int versionCode = 0; try { versionCode = getPackageManager().getPackageInfo((), 0).versionCode; } catch (NameNotFoundException e) { (); } ("", "-------" + () + "-------" + versionCode);//Get the current package name List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); for (int i = 0; i < (); i++) { PackageInfo p = (i); ("", "-------" + + "-------" + + "--------" + + "-------" + ); if ((!getSysPackages) && ( == null)) { continue; } if ((PACKAGENAME)) { packageExist = true; break; } } return packageExist; } //Installing APK private void installApk() { if (checkFileExist(fileRoot + fileName)) { Intent intent = new Intent(); (Intent.FLAG_ACTIVITY_NEW_TASK); (.ACTION_VIEW); String type = "application/-archive"; (("file://" + fileRoot + fileName), type); startActivity(intent); } else { downloadapk(); } }
Through the above code and some online download code, you can create a simplified application market.
I hope this article will be helpful to everyone's Android programming design.