0

Hi I am using the following code to show the user direction between his current location and his car location.

 String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f(%s)&daddr=%f,%f (%s)", curLat, curLong, "Your location", carLat, carLong, "Your vehicle location");
 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
 intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
 startActivity(intent);

This works well but I need to press on start navigation before entering into navigation activity. What I want is I need to enter the navigation activity directly without pressing the start navigation button.

As u can see below. The image on left is what I get first. On clicking the start navigation button at bottom I am then taken to turn by turn navigation (image on right). Is it possible to directly go to turn by turn navigation of the default android app directly ?.

enter image description here

user3389247
  • 271
  • 1
  • 3
  • 10

1 Answers1

8

Ey, I just faced this problem, and you can avoid the "button click" action by changing the URI that you are sending on your Intent.

Try to do this :

LatLng destiny; // Your destiny LatLng object 
String uri = "google.navigation:q=%f, %f";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String
            .format(Locale.US, uri, destiny.latitude, destiny.longitude)));
if (canHandleIntent(this, navIntent))
    startActivity(navIntent);
else
    Toast.makeText(this, "Please install Google Navigation",
        Toast.LENGTH_LONG).show();

Then, if you have multiple apps to deal with navigation processes and you want to go directly for google Navigation, you can also include the line with the "setClassName" call to the activity:

 intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

Hope it helps ;)