最近做一个项目,有一个需要启动第三方应用,和微信的地图查看差不多,需要启动高德,百度或腾讯地图来查看;特来分享,希望有所帮助。
案例效果如图:
要想启动第三方;首先要知道他的包名
一:高德
高德:com.autonavi.minimap
高德接口说明:http://lbs.amap.com/api/amap-mobile/guide/android/route
你可以验证存不存在,不存在则可提示相关信息;
if (isInstallByread("com.autonavi.minimap")) { //跳转处理 }else { Toast.makeText(MainActivity.this,"未安装该应用",Toast.LENGTH_LONG).show(); } private boolean isInstallByread(String packageName) { return new File("/data/data/" + packageName).exists(); }
高德文字规划路线
//单独导航 Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse("amapuri://route/plan/?dlat=39.98848272&dlon=116.47560823&dev=0&t=0")); //"androidamap://navi?sourceApplication=appname&poiname=fangheng&lat=26.57&lon=106.71&dev=1&style=2" // amapuri://route/plan/?sname=A&did=BGVIS2&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&t=0 intent.setPackage("com.autonavi.minimap"); //context.startActivity(intent); //反地理编码 /*Intent inten1 = new Intent("android.intent.action.VIEW" , android.net.Uri.parse("androidamap://viewReGeo?sourceApplication=softname&lat=26.57&lon=106.71&dev=1")); inten1.setPackage("com.autonavi.minimap");// pkg=com.autonavi.minimap inten1.addCategory("android.intent.category.DEFAULT"); context.startActivity(inten1);*/
//地理编码 Intent inten2 = new Intent("android.intent.action.VIEW",
android.net.Uri.parse("androidamap://keywordNavi?sourceApplication=softname&keyword=贵州省贵阳市&style=2")); inten2.setPackage("com.autonavi.minimap"); inten2.addCategory("android.intent.category.DEFAULT"); startActivity(inten2);
二:百度
百度:com.autonavi.minimap
百度接口说明:http://lbsyun.baidu.com/index.php?title=uri/api/android
// Intent intent = Intent.getIntent("intent://map/direction?origin=latlng:26.58&destination=latlng:26.57&mode=transit&src=某某公司#Intent;" + "scheme=bdapp;package=com.baidu.BaiduMap;end"); //Intent intent = Intent.getIntent("intent://map/direction?origin=" + loc1 + "&destination=" + loc2 + "&mode=transit&src=某某公司#Intent;" + "scheme=bdapp;package=com.baidu.BaiduMap;end"); //Intent intent = Intent.getIntent("intent://map/direction?destination=latlng:26.57+106.71&mode=transit&src=某某公司#Intent;" + "scheme=bdapp;package=com.baidu.BaiduMap;end"); //起点 此处不传值默认选择当前位置 Intent intent = Intent.getIntent("intent://map/direction?destination=贵阳市粮食局&mode=driving&src=XX科技有限公司#Intent;" + "scheme=bdapp;package=com.baidu.BaiduMap;end"); /* Intent intent =new Intent(); intent.setData(Uri.parse("baidumap://map/direction?destination=26.57,106.71&mode=driving"));*/ startActivity(intent);
三:腾讯
腾讯接口说明:腾讯开发平台查看或者下载源码,源码中包含了各种方式的接口文档
Intent intent =new Intent(); //intent.setData(Uri.parse("qqmap://map/routeplan?type=drive&from=天坛南门&fromcoord=39.873145,116.413306&to=国家大剧院&tocoord=39.907380,116.388501")); intent.setData(Uri.parse("qqmap://map/search?keyword=贵州省贵阳市")); //qqmap://map/geocoder?coord=39.904956,116.389449 //经纬度 //qqmap://map/search?keyword=小肥羊&bound=39.907293,116.368935,39.914996,116.379321 //搜索附件 startActivity(intent);