Android - Как вызвать намеренные автономные навигационные приложения с несколькими путевыми точками?
Сегодня я использую Android Intent в следующем формате для запуска навигации из моего приложения в автономных навигационных приложениях: Action: "android.intent.action.VIEW" URI: "google.navigation:q=48.605086,2.367014/48.607231,2.356997" Компонент Имя навигационного приложения: например, Google Maps "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
Я хочу запустить навигацию с несколькими путевыми точками. Возможно ли это на TomTom Go Mobile, Google Maps, Waze, Here WeGo и Sygic через Intent?
Can I trigger navigation on the application above and start driving automatically? Without user interaction?
I tried to trigger the above intent via ADB and do some tweaking by adding ",", ";", "and". Ничего не получалось.
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)
}
}
Waze:
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)
}
}