Android intent for opening both Waze and Google maps

There are a few similar posts but I couldn’t find an exact one. basically, I want to open both Google maps and Waze with the same intent. At first I tried this:

final String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

Waze navigated directly to the right location and Google maps opened the right place. then I realized that Google maps doesn’t put a pin on the location so it’s hard for the user to know where it is exactly. So I looked around and realized that Google maps requires the “?q=..(label)” for that… I changed the uri construction to:

  • Installing Android Studio, does not point to a valid JVM installation error
  • How to remove Rendering Problems message window in Intellij IDEA 13 layout preview
  • android notifyItemRangeInserted disable autoscroll
  • do I need a wake lock in my broadcastreceiver if I'm not starting a service or an activity?
  • Android TextureView.getBitmap() is very slow
  • Using HashMap to map a String and int
  • final String uri = String.format(Locale.ENGLISH, "geo:%f,%f?q=%f,%f (%s)", latitude, longitude, latitude, longitude, name);
    

    But then Waze did 2 things: navigated to the right place AND run a search on the label. This required the user to click the back button to close the search results screen and remain with the navigation to the right place.

    I looked everywhere for an answer but failed to find a solution that will achieve both.
    At first I thought that it’s not possible and Waze has a bug… but then I noticed that Facebook messenger is doing exactly what I want. when clicking on a message with a location it will open both apps: Google maps will have a pin (with a label) and Waze will navigate straight to that location without running a search.

    Few questions about the above:
    1. (Of course) How can I achieve that?
    2. How can I know how the Facebook messenger’s intent being built? (Can I catch it in anyway)
    3. What’s the reason behind having the label only with the “?q=..”?

    Thanks

    Related posts:

    ProgressDialog : how to prevent Leaked Window
    How to access `this` inside a renderRow of a ListView?
    ActionBar capacity/overflow not changing on orientation change
    Using VideoView, how to remove “can't play this video” alert message?
    Using ListView or GridView dynamically based on Layout Used By Device
    Using icons in Android preferences
  • Android RecyclerView last item remove (runtime) error
  • onMeasure custom view explanation
  • Switching from AndEngine to libgdx - what to know?
  • Eclipse Android Plugin — libncurses.so.5
  • upload picture to emulator gallery
  • Show <ul> <li> in android textview
  • 2 Solutions collect form web for “Android intent for opening both Waze and Google maps”

    Never mind. I was able to intercept the Facebook messenger with the below app and figured that the URI should be as follows:

    String.format(Locale.ENGLISH, "geo:0,0?q=") + android.net.Uri.encode(String.format("%s@%f,%f", label, latitude, longitude), "UTF-8");
    

    The app:
    https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc.android.intentintercept&feature=search_result#?t=W251bGwsMSwyLDEsInVrLmNvLmFzaHRvbmJyc2MuYW5kcm9pZC5pbnRlbnRpbnRlcmNlcHQiXQ..

    Thanks

    Following Nimrod’s tip I’ve installed the app and intercepted the intent from whatsapp’s location feature. Here’s the full Intent tested on maps and waze:

        String uri = "http://maps.google.com/maps?q=loc:"+latitude+","+longitude+" ("+label+")";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
        intent.setData(Uri.parse(uri));
        startActivity(intent);
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.