3

Since Waze and Google Maps have different URI formats, I need to create two separate intents in order to make sure that apps will navigate user to the correct location.

The main problem: I don't want to make user select navigation app every time. I want it to behave like this: if user has default navigation app set - use it without asking.

How to have two URIs for separate apps but still have the same interface just like when starting intent with ACTION_VIEW parameter?

This is my code that I am working with. Currently navigation works fine, but user is being asked every time to select navigation app:

if (!StringUtils.isEmpty(address)) {
    String q = address + "&mode=d&navigate=yes&geo=" + address + "&ll=" + address;
    String urlWaze = "https://waze.com/ul?q=" + q;
    Intent wazeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlWaze));

    String urlGoogle = "google.navigation:q=" + q;
    Intent googleMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlGoogle));
    googleMapsIntent.setPackage("com.google.android.apps.maps");

    String title = getActivity().getResources().getString(R.string.choose_navigation_app);
    Intent chooserIntent = Intent.createChooser(wazeIntent, title);
    Intent[] arr = new Intent[1];
    arr[0] = googleMapsIntent;
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);

    getContext().startActivity(chooserIntent);
} else {
    Toast.makeText(getContext(), getString(R.string.waypoint_not_have_geolocation), Toast.LENGTH_SHORT).show();
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Marius
  • 119
  • 8
  • 1
    Take a look at [this](https://stackoverflow.com/a/23172341/6950238) answer of [keyser](https://stackoverflow.com/users/645270/keyser). – Andrii Omelchenko Jul 31 '18 at 12:03
  • @AndriiOmelchenko thank you but this is not an option since I am dealing with different URI's for separate intents. – Marius Jul 31 '18 at 12:18
  • But you can determine what app is default and use Intent with appropriate URI for it. – Andrii Omelchenko Jul 31 '18 at 12:27
  • @AndriiOmelchenko as keyser mentioned - the output is "fishy" and is not reliable. – Marius Jul 31 '18 at 12:50
  • 1
    Sad, but at least you can create custom App Chooser (like [this](https://www.codeproject.com/Tips/1097808/Custom-App-Chooser-in-Android) or [that](https://stackoverflow.com/a/25217145/6950238)) with "use as default" CheckBox and ask user only first time... Also take a look at [this](https://stackoverflow.com/a/47325632/6950238). – Andrii Omelchenko Jul 31 '18 at 12:58
  • @AndriiOmelchenko thank you for the ideas. I have already thought about it, and I used your last url to determine how to come up with my current solution. It's crazy how waze is owned by Google and yet there is no information on how to have one url for both waze and google maps. – Marius Jul 31 '18 at 13:15

1 Answers1

0

As it turns out Waze and Google Maps have very different URIs and in ordet to resolve situation that I descibed in my question, the only solution was to create separate user-settings in my application.

Marius
  • 119
  • 8