Google Maps URL Schema Control not working on Android

I am trying to call an external application Google Mapsfrom my application Android.

Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" + stringLatitude + "," + stringLongitude + "&daddr=" + latitud + "," + longitud+"&dirflg=d"));

startActivity(mIntent);

It works great on Android 2.3.6.

But not on Android 4.2, the first time I press the button that runs this code Google Maps, it opens correctly, but nothing is displayed about the driving mode.

But as soon as I return to the main application, I press the button again, everything works fine. This only happens on the first try.

I can not understand what is happening

Any clue?

+4
source share
1 answer

I am using the following code working perfectly on android 4.2

Intent i = new Intent(android.content.Intent.ACTION_VIEW, 
           Uri.parse("http://maps.google.com/maps?saddr="+a+","+b+"&daddr="+c+","+d+"&mode=driving"));
i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(i);
+1

Source: https://habr.com/ru/post/1530398/


All Articles