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百度地圖方式舉例