Android判读是否安装了某一款APP

时间:2022-02-13 10:48:23
    /**
* @Title: isAvilible
* @Description: 断手机已安装某程序
* @param @param context
* @param @param packageName
* @param @return
* @return boolean
* @throws
*/
public static boolean isAviliblePackage(Context context, String packageName){
final PackageManager packageManager = context.getPackageManager();//获取packagemanager
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);//获取所有已安装程序的包信息
List<String> pName = new ArrayList<String>();//用于存储所有已安装程序的包名
//从pinfo中将包名字逐一取出,压入pName list中
if(pinfo != null){
for(int i = 0; i < pinfo.size(); i++){
String pn = pinfo.get(i).packageName;
pName.add(pn);
}
}
return pName.contains(packageName);//判断pName中是否有目标程序的包名,有TRUE,没有FALSE
}