27

In my application I have an option to start navigation to selected POI. Basically what I want is to launch a turn-by-turn navigator from my application. The thing is I don't know which (if any) navigator is installed.

So, the question is how to start an intent by showing a list of suitable activities for navigation to the user first, letting him choose which one he would like to use? Also would be nice to find a way to pass extra parameters to selected activity (this sounds like an issue to me, since different navigation apps use different names for their extras, I guess).

In case it's not clear: I'm looking for a way to DISPLAY A LIST OF SUITABLE APPLICATIONS FOR NAVIGATION WITH THE OPTION TO MAKE ONE DEFAULT.

EDIT: Find here the implementation http://datamoil.blogspot.com/2011/04/android-universal-intent-to-start.html

Ilya Saunkin
  • 18,934
  • 9
  • 36
  • 50

4 Answers4

21

The bad news is, there isn't a standard Intent URI for navigation.

Yes, google.navigation URIs exist, and an app may choose to support it.

The best solution I can think of is to:

  • Explicitly check for known apps
  • Implicitly check for apps hooking google.navigation: and perhaps geo: (but then you also get map apps)

You can enumerate the possible implicit targets using PackageManage.queryIntentActivities

Phil Lello
  • 8,377
  • 2
  • 25
  • 34
  • Unfortunately, you are right. I followed your suggestion and implemented it. It's not the most elegant solution, yet it works and does pretty much what I expected. – Ilya Saunkin Apr 29 '11 at 13:00
12

Try:

Intent intent = new Intent(Intent.ACTION_VIEW, 
    Uri.parse("google.navigation:q=New+York+NY")); 
startActivity(intent);
JJD
  • 50,076
  • 60
  • 203
  • 339
pumpkee
  • 3,357
  • 3
  • 27
  • 34
  • Thanks for the effort, that's not what I'm looking for. Google Navigation only works in the USA and it is not necessarily the preferred navigation application. I think I was clear in my question that I'm looking for a way to DISPLAY A LIST OF SUITABLE APPLICATIONS FOR NAVIGATION. – Ilya Saunkin Apr 27 '11 at 09:37
  • 2
    It all depends which intent filters the navigation apps are using. AFAIK there is no specific CATEGORY for nav intents. The nav apps that i have on my phone catch the intent i just posted. So when i call it, i get a list of different apps, not just google navigation. – pumpkee Apr 27 '11 at 10:09
  • 2
    Every smart nav app should be registered for this intent, because its the one maps calls when you pick an adress and click navigate to. – pumpkee Apr 27 '11 at 10:26
  • 2
    Apparently not every. E.g. Navigon has a public intent to do that. http://www.navigon.com/portal/common/faq/files/online_documents/NAVIGON_Android_public_Intent.pdf – Ilya Saunkin Apr 27 '11 at 10:39
5

First I used in my onTap method inside the button's listener:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY")); 
mContext.startActivity(i);

Then in manifest simply use:

<activity android:name=".LaunchGPS" android:screenOrientation="portrait">
  <intent-filter>       
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

This will open any Navigator App your phone has such as VZ Navigagtor, Google or whatever the phone is loaded with. Worked for me the first time perfectly. Hope this solves your problem.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Larry Enzer
  • 51
  • 1
  • 1
0

I found more advantages using this code (just for to show available navigator apps)

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:"));
if (intent.resolveActivity(getActivity().getPackageManager()) != null)   {
    startActivityForResult(Intent.createChooser(intent, "Continues with:", CHOOSE_NAVIGATOR_ID);
} else {
   // Handle failure...
}
Lorenzo
  • 116
  • 1
  • 5
  • 1
    Can you please explain the code? I know nothing about Java. –  Oct 13 '17 at 14:12
  • I'm using intent objects to 'filter' the applications currently installed in the phone that can interpret this type of scheme (typically map or navigator applications). This action is delegated to the resolveActivity method that actually checks if there is at least one application that can interpret this URI. If it is present will be created a 'chooser' , that is a particular clickable list with the various compatible application icons, at the touch of one of them it will be sent to its app with the parameters previously defined in the URI. – Lorenzo Oct 14 '17 at 16:10