Navigation with Waze and Google Maps using Intent.createChooser shows Waze icon twice
Asked Answered
J

1

7

I'm creating this question after finding the answer, I was not sure about the etiquette, but it seems to be OK (plus, I see now there's a built-in option).

The problem was as described in the title, we created an intent chooser using code that resembles this:

String url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes";
Intent intentWaze = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
Intent intentGoogleNav = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));

String title = context.getString(R.string.title);
Intent chooserIntent = Intent.createChooser(intentGoogleNav, title);
Intent[] arr = new Intent[1];
arr[0] = intentWaze;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
context.startActivity(chooserIntent);

And got two Waze icons and one Google Maps icon; and worse, one of the Waze icons did not start the navigation (only open the app).

We could not use the geo: intent because we need to control the intents shown (we don't want to show both intents at all times) and the navigation type in Google Maps (for example: &mode=w).

Joanjoana answered 16/11, 2017 at 9:13 Comment(0)
J
14

After some time I used the solution found here, and there was only one icon that was working properly. As I wrote in the question, I could not use this solution because it lacks the flexibility I needed, so after looking at the code I saw that what was missing was this:

intentWaze.setPackage("com.waze");
// and more importantly, this:
intentGoogleNav.setPackage("com.google.android.apps.maps");

It seems that Waze is listening to the Google Maps intent (and does not work well with it), and that's why there were two icons.

Joanjoana answered 16/11, 2017 at 9:13 Comment(1)
this is awesome.Astred

© 2022 - 2024 — McMap. All rights reserved.