Open navigation activity directly of deafault android map programmatically - Android - android

Hi I am using the following code to show the user direction between his current location and his car location.
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f(%s)&daddr=%f,%f (%s)", curLat, curLong, "Your location", carLat, carLong, "Your vehicle location");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
This works well but I need to press on start navigation before entering into navigation activity. What I want is I need to enter the navigation activity directly without pressing the start navigation button.
As u can see below. The image on left is what I get first. On clicking the start navigation button at bottom I am then taken to turn by turn navigation (image on right). Is it possible to directly go to turn by turn navigation of the default android app directly ?.

Ey, I just faced this problem, and you can avoid the "button click" action by changing the URI that you are sending on your Intent.
Try to do this :
LatLng destiny; // Your destiny LatLng object
String uri = "google.navigation:q=%f, %f";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String
.format(Locale.US, uri, destiny.latitude, destiny.longitude)));
if (canHandleIntent(this, navIntent))
startActivity(navIntent);
else
Toast.makeText(this, "Please install Google Navigation",
Toast.LENGTH_LONG).show();
Then, if you have multiple apps to deal with navigation processes and you want to go directly for google Navigation, you can also include the line with the "setClassName" call to the activity:
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
Hope it helps ;)

Related

Open google maps activity from my application and if user reaches the destination redirect the user to my app

I want to open google maps turn by turn direction screen on button click and want to check if user reaches the destination redirect the user to my app currently i am using this code to open google maps
String uri = String.format(Locale.ENGLISH, "geo:0,0?q="+ destinationLoc.latitude+","+destinationLoc.longitude
+ "(The Embroidery Store)" );
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I want to redirect the user to my app after he reaches the destination.
You may want to look into the concept of geo-fencing.
The following links might help:
https://developer.android.com/training/location/geofencing.html
https://github.com/googlesamples/android-Geofencing

Launch Google Navigation without routes choosing

I am launching Google Navigation with intent:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + mCity));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
It build route from my current location to destination city. But sometimes it give me few routes. Is there way to force give me always only one route?
It is just launching Google Navigation app with destination and current address, so it will depend on user to choose one route as is case with regular navigation app.

Launch directly the directions on Google Maps

I want to launch the Google Maps app from my android application with the driving directions view.
I gone through the following posts but they don't serve my purpose.
Launch Google Maps to show road directions
How to programmatically launch map appliction in android to show direction?
I tried the following code...
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?f=d&daddr=51.448,-0.972"));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
Which gives me the following view,
Then I need to click 'Get Directions' button to get the following view,
And then I need to click 'DIRECTIONS LIST' to get the following view,
Is there a way to directly launch the 3rd view (as above) from my android application?
Yes You can directly open direction view Using google.navigation.
Just pass Destination address and it will give direction from current location to destination address:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=destination address"));
startActivity(intent);

Back to my application when call direction from google map in Android

I have an application get direction via google map. Example Activity A call google map:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(myuri));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
It show
Image 1: http://flic.kr/p/eBnRCy
then show
Image 2: http://flic.kr/p/eBjGWn
How to from image 2, I can back again my application(Activity A), don't back again image 1. Thanks a lot.
You may try to hack it with Intent.FLAG_ACTIVITY_NO_HISTORY, which removes first Activity as soon as a second is opened. This will work if the two screens you put into question are two instances of Activity (even if they are the same class).

Open default navigation app using an address

How can i start an Intent to open either the default navigation application (e.g. Google Navigation or Google Maps) or give the user the opportunity to select among navigation applications.
Thanks in advance.
You have to use an Intent with ACTION_VIEW and the geo data scheme.
The problem using geo:latitude,longitude is that Google Maps only centers at your point, without any pin or label.
That's quite confusing, especially if you need to point to a precise place or/and ask for directions.
If you use the query parameter geo:lat,lon?q=name in order to label your geopoint, it uses the query for search and dismiss the latitude and longitude parameters.
I found a way to center the map with latitude and longitude and display a pin with a custom label, very nice to display and useful when asking for directions or any other action:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=37.423156,-122.084917 (" + name + ")");
startActivity(intent);
This intent is from the list of official "G apps" intent list here.
Try:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY")); startActivity(i);
Or use this, this way the stardard navigation app will be launched:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
Add this line before startActivity if you don't want the popup dialog:
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
Also see: How to check programmatically if an application is installed or not in Android? and Android: detect when app is installed, you can make your own Window so the user can choose between some application.

Categories

Resources