Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are the different methods I found so far:</p> <p><strong>1. Directly start the navigation:</strong></p> <p>This explicit intent will directly launch Google Navigation:</p> <pre><code>Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=my+street+address"); startActivity(intent); </code></pre> <p>This will directly start the navigation (unfortunately without giving the user a choice of transportation means)</p> <p>.</p> <p><strong>2. Let the user select the transportation means:</strong></p> <p>This will launch the Google navigation app, but lets the user select the transportation means before starting the navigation:</p> <pre><code>Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps/?daddr=my+street+address"); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent); </code></pre> <p>. </p> <p><strong>3. Start on the Google map:</strong></p> <pre><code>Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=my+street+address"); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent); </code></pre> <p>This will launch Maps, from where the user can start the navigation (and select the transportation mode).</p> <p>In all cases, you should either use PackageManager and queryIntentActivities() or exception handling to handle cases where the user does not have Google Maps/Navigation installed.</p> <p>In my app I use method 2 which works just fine. Hope this helps.</p> <p>Add-on: Here's a method to check whether an app is installed or not. I use this to check if "com.google.android.apps.maps" is installed before calling intent.setClassName().</p> <pre><code>public static boolean isAppInstalled(String uri) { PackageManager pm = getContext().getPackageManager(); boolean app_installed = false; try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload