最近須要作一個關於導航的功能,得用手機存在的地圖來打開,而後從網上找了一篇博客裏面只寫了怎麼判斷手機是否安裝百度地圖的,從網上各類翻,終於在高德地圖上找到一句話。android
開發者在調用URI 以前須要先判斷是否安裝了高德地圖APP。若是沒有安裝,下載安裝高德地圖。而後調用相關地圖功能,如周邊實時路況信息顯示,示例以下:ide
Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse("androidamap://showTraffic?sourceApplication=softname&poiid=BGVIS1&lat=36.2&lon=116.1&level=10&dev=0")); intent.setPackage(「com.autonavi.minimap」); startActivity(intent);
而後綜合網上那篇博客代碼以下,.net
/** * 檢查手機上是否安裝了指定的軟件 * @param context * @param packageName:應用包名 * @return */ private boolean isAvilible(Context context, String packageName){ //獲取packagemanager final PackageManager packageManager = context.getPackageManager(); //獲取全部已安裝程序的包信息 List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0); //用於存儲全部已安裝程序的包名 List<String> packageNames = new ArrayList<String>(); //從pinfo中將包名字逐一取出,壓入pName list中 if(packageInfos != null){ for(int i = 0; i < packageInfos.size(); i++){ String packName = packageInfos.get(i).packageName; packageNames.add(packName); } } //判斷packageNames中是否有目標程序的包名,有TRUE,沒有FALSE return packageNames.contains(packageName); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.common_right: //若是已安裝, if(isAvilible(mcontext,"com.baidu.BaiduMap")) {//傳入指定應用包名 WinToast.makeText(mcontext,"即將用百度地圖打開導航").show(); Uri mUri = Uri.parse("geo:"+jingdu+","+weidu+"?q="+title); Intent mIntent = new Intent(Intent.ACTION_VIEW,mUri); startActivity(mIntent); }else if(isAvilible(mcontext,"com.autonavi.minimap")){ WinToast.makeText(mcontext,"即將用高德地圖打開導航").show(); Uri mUri = Uri.parse("geo:"+jingdu+","+weidu+"?q="+title); Intent intent = new Intent("android.intent.action.VIEW",mUri); startActivity(intent); }else { WinToast.makeText(mcontext,"請安裝第三方地圖方可導航").show(); return; } break; default: break; } }
我這裏判斷了高德和百度的,但願能幫到大家code