Here are some methods that I have found so far:
1. Directly start navigation:
This clear intention will directly launch Google Navigation:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=my+street+address"); startActivity(intent);
This will lead to a direct start of navigation (unfortunately, without giving the user the choice of transport)
.
2. Let the user select a vehicle:
This will launch the Google navigation application, but allows the user to select vehicles before starting navigation:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps/?daddr=my+street+address"); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent);
.
3. Start with a Google map:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=my+street+address"); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent);
This will launch Maps, from where the user can start navigation (and select the mode of transportation).
In all cases, you should use PackageManager and queryIntentActivities () or exception handling to handle cases when the user does not have Google Maps / navigation installed.
In my application, I use method 2, which works fine. Hope this helps.
Add-on: Here you can check whether the application is installed or not. I use this to check if "com.google.android.apps.maps" is set before calling aim.setClassName ().
public static boolean isAppInstalled(String uri) { PackageManager pm = getContext().getPackageManager(); boolean app_installed = false; try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; }