Android - How to trigger standalone navigation applications with multiple way points via intent?

729 views Asked by At

Today I'm using Android Intent in the following format to trigger navigation from my application on standalone navigation applications: Action : "android.intent.action.VIEW" URI : "google.navigation:q=48.605086,2.367014/48.607231,2.356997" Component Name of the navigation app : For example Google Maps "com.google.android.apps.maps/com.google.android.maps.MapsActivity"

For example:

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

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

  1. I want to trigger navigation with multiple way points, Is it possible on TomTom Go Mobile, Google Maps, Waze, Here WeGo and Sygic via Intent ?

  2. 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". Nothing worked.

1

There are 1 answers

3
no_name On

In order to open the navigation mode in the HERE WeGo app you can use the following function

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)
    }
}

You can also resolve the installed apps that can be used for navigation and let the user decide which one s/he wants to use:

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)
    }
}