Android判断应用程序是否安装和版本号

jopen 10年前

    /**        * @Title: isPackageExists        * @Description:         *      判断应用是否安装,传递的是应用的包名        *         * @param targetPackage        * @return              * @throws        */        public boolean isPackageExists(String targetPackage) {            List<ApplicationInfo> packages;            PackageManager pm;            pm = getPackageManager();            packages = pm.getInstalledApplications(0);            for (ApplicationInfo packageInfo : packages) {                Log.d("", "####package name : " + packageInfo.packageName);                 if (packageInfo.packageName.equals(targetPackage)) {                    return true;                }            }            return false;        }                /**        * 获取应用版本号        * @return 当前应用的版本号        */        public String getVersion() {            try {                PackageManager manager = this.getPackageManager();                PackageInfo info = manager.getPackageInfo("com.sina.weibo", 0);                String version = info.versionName;                return "###版本号为 : " + version;            } catch (Exception e) {                e.printStackTrace();                return "####找不到";            }        }