首页 > 代码库 > 检查应用是否安装

检查应用是否安装

private boolean isAvilible(Context context, String packageName) {
if (packageName == null || "".equals(packageName))
return false;
PackageManager pageManage = getPackageManager();
List<PackageInfo> packages = pageManage.getInstalledPackages(0);
for (int i = 0; i < packages.size(); i++) {
PackageInfo packageInfo = packages.get(i);
String appName = packageInfo.applicationInfo.loadLabel(
getPackageManager()).toString();
String pagName = packageInfo.packageName;
if (appName.contains(packageName)) {
return true;
}
}
return false;

}



/**
* 检测该包名所对应的应用是否存在

* @param packageName
* @return
*/
public boolean checkPackage(String packageName) {
if (packageName == null || "".equals(packageName))
return false;
try {
getPackageManager().getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}

检查应用是否安装