跳转第三方地图App进行导航
/**
* type
* 1 高德地图com.autonavi.minimap
* 2 百度地图com.baidu.BaiduMap
* 3 腾讯地图com.tencent.map
*
*/
private fun goNavigation(type: Int,lat: Double, lon: Double,title:String, appName:String): Intent? {
when (type) {
1 ->{// sb 拼接跳转至高德地图需要的参数
val sb = StringBuilder("androidamap://route?sourceApplication=").append(appName)
sb.append("&dlat=").append(lat).append("&dlon=").append(lon).append("&dname=").append(title).append("&dev=0&m=0&t=0")
return Intent("android.intent.action.VIEW", Uri.parse(sb.toString())).setPackage("com.autonavi.minimap")
}
2 ->{// sb 拼接跳转至百度地图需要的参数
val sb = StringBuilder("baidumap://map/geocoder?")
sb.append("location=").append(lat).append(",").append(lon).append("&name=").append(title).append("&coord_type=gcj02")
return Intent().setData(Uri.parse(sb.toString())).setPackage("com.baidu.BaiduMap")
}
else ->{// sb 拼接跳转至腾讯地图需要的参数
val sb = StringBuilder("qqmap://map/routeplan?type=drive&referer=").append(appName)
sb.append("&tocoord=").append(lat).append(",").append(lon).append("&to=").append(title)
return Intent( ).setData( Uri.parse(sb.toString()))
}
}
}
检测是否安装App
/**
* 检索是否有对应app
*/
fun isApp(packageName: String?): Boolean {
//获取packagemanager
val packageManager =activity?.packageManager
//获取所有已安装程序的包信息
val packageInfos = packageManager?.getInstalledPackages(0)
//用于存储所有已安装程序的包名
val packageNames: MutableList = ArrayList()
//从pinfo中将包名字逐一取出,压入pName list中
if (packageInfos !=null) {
for (iin packageInfos.indices) {
val packName =packageInfos[i].packageName
packageNames.add(packName)
}
}
//判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE
return packageNames.contains(packageName)
}