0

I am able to launch Google Maps intent with

Uri location = Uri.parse("geo:0,0");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
startActivity(mapIntent);

How can I launch the intent in Driving mode (with no destination, unless previously set in Maps) so that it looks like on the screenshot below?

enter image description here

I tried setting mode=driving but that just opens the regular map with the "driving" tab selected:

 Uri location = Uri.parse("geo:0,0?mode=driving");
xomena
  • 31,125
  • 6
  • 88
  • 117
Maxim Neaga
  • 921
  • 3
  • 17
  • 29

2 Answers2

6

This will launch google maps in Driving Mode

    Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.apps.maps");
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("google.navigation:/?free=1&mode=d&entry=fnls"));
    startActivity(intent);
  • I know this is old, but how did you get that google.navigation:/?free...? I mean, I need something similar with another application I want to know how to extract that. Thanks – barbudito Jun 17 '18 at 17:26
  • Is there anyway to forcefully cancel the ongoing navigation and start the one specified by intent? – dpaksoni Aug 24 '18 at 06:06
3

I understand you would like to open a Google Maps app in navigation mode. For this purpose you can use an URL described in the Google Maps URLs API:

https://developers.google.com/maps/documentation/urls/guide#directions-action

The following code should do a trick, and I believe you need to provide a destination parameter to open this mode directly

String URL = "https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination=Los+Angeles";
Uri location = Uri.parse(URL);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
startActivity(mapIntent);

I hope this helps!

xomena
  • 31,125
  • 6
  • 88
  • 117
  • You are right, it requires the destination to use travelmode=driving. I wonder if there is a way to get in the driving mode without destination, like described here: http://fieldguide.gizmodo.com/google-maps-driving-mode-is-your-essential-in-car-ai-1776306949 – Maxim Neaga Aug 14 '17 at 15:34