【问题标题】:Android - How to trigger standalone navigation applications with multiple way points via intent?Android - 如何通过意图触发具有多个航点的独立导航应用程序?
【发布时间】:2019-12-12 09:52:29
【问题描述】:

今天,我使用以下格式的 Android Intent 在独立导航应用程序上从我的应用程序触发导航: 行动:“android.intent.action.VIEW” URI:“google.navigation:q=48.605086,2.367014/48.607231,2.356997” 导航应用的组件名称:例如谷歌地图“com.google.android.apps.maps/com.google.android.maps.MapsActivity”

例如:

Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

来自:https://developers.google.com/maps/documentation/urls/android-intents

  1. 我想通过多个航点触发导航,是否可以通过 Intent 在 TomTom Go Mobile、Google Maps、Waze、Here WeGo 和 Sygic 上使用?

  2. 我可以在上面的应用程序上触发导航并自动开始驾驶吗?没有用户交互?

我尝试通过 ADB 触发上述意图,并通过添加“,”,“;”,“and”进行一些调整。没有任何效果。

【问题讨论】:

标签: google-maps here-api waze tomtom sygic


【解决方案1】:

为了在 HERE WeGo 应用中打开导航模式,您可以使用以下功能

private fun navigateToDestination(destination: GeoCoordinate) {
    try {
        val intent = Intent().apply {
            action = "com.here.maps.DIRECTIONS"
            addCategory(Intent.CATEGORY_DEFAULT)
            data = Uri.parse("here.directions://v1.0/mylocation/${destination.latitude},${destination.longitude}")
        }
        intent.resolveActivity(packageManager)?.let {
            startActivity(intent)
        }
    } catch (t: Throwable) {
        Timber.e(t)
    }
}

Sygic:

private fun navigateToDestination(destination: GeoCoordinate) {
    try {
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse("com.sygic.aura://coordinate|${destination.longitude}|${destination.latitude}|drive"))
        intent.resolveActivity(packageManager)?.let {
            startActivity(intent)
        }
    } catch (t: Throwable) {
        Timber.e(t)
    }
}

位智:

private fun navigateToDestination(destination: GeoCoordinate) {
    try {
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse("waze://?ll=${destination.latitude}, ${destination.longitude}&navigate=yes"))
        intent.resolveActivity(packageManager)?.let {
            startActivity(intent)
        }
    } catch (t: Throwable) {
        Timber.e(t)
    }
}

您还可以解析已安装的可用于导航的应用程序,让用户决定要使用哪个:

private fun navigateToDestination(destination: GeoCoordinate) {
    try {
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=${destination.latitude}, ${destination.longitude}"))
        val resolvedPackages = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)
        if (resolvedPackages.isNotEmpty()) {
            val packageNames = resolvedPackages.map { it.activityInfo.packageName }
            val targetIntents = packageNames.map { packageManager.getLaunchIntentForPackage(it) }
            val intentChooser = Intent.createChooser(Intent(), "Choose a navigation app")
            intentChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toTypedArray())
            startActivity(intentChooser)
        }
    } catch (t: Throwable) {
        Timber.e(t)
    }
}

【讨论】:

  • 感谢您的回答。那么以上内容适用于多个目的地吗?关于 TomTom Go 的任何线索?
  • 根据 tomtom (developer.tomtom.com/bridge/develop/system-intents) 的文档,URI 方案与上面最后一个函数中使用的方案相同,例如。 google.navigation:q=,。我还没有尝试过多个目的地。
  • TomTom Go Mobile 和 TomTom Bridge 是不同的产品。您提供的链接指向 Bridge 文档。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-14
  • 2020-05-03
  • 1970-01-01
相关资源
最近更新 更多