public static boolean isAvilible(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 }
if(BaiduTool.isAvilible(Setting_activity.this.getApplicationContext(), "com.baidu.BaiduMap")){ try { intent = Intent.getIntent("intent://map/direction?origin=latlng:"+BaiduTool.getInstance().getLocationX()+","+BaiduTool.getInstance().getLocationY()+"|name:我的位置&destination= &mode=transit®ion=青岛&src=移动医疗护理#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end"); } catch (URISyntaxException e) { ToastUtils.show(getApplicationContext(), "调用百度地图失败."); Log.i("BaiduToolisAvilible", "未安装"); } startActivity(intent); } //未安装,跳转至market下载该程序 else { //未安装百度地图,跳转应用商店. ToastUtils.show(getApplicationContext(), "未安装百度地图,跳转应用商店."); Uri uri = Uri.parse("market://details?id=com.baidu.BaiduMap");//id为包名 Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); } //移动APP调起Android百度地图方式举例