I have an app that makes use of the following intent in order to display a set of places on Google Map and start direction based on user choice:
Intent intent =
new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=" + Uri.encode("mykeyword") + "&z=14"));
// force to use Google maps
intent.setClassName(
"com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
The intent is started as follows:
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")));
}
The code is triggered by my app activity that is displayed on the lock screen (thanks to the android:showOnLockScreen="true" property). It means the device is locked when the intent is used.
Unfortunately, the intent requires the user to unlock the device in order to have access to the Google Map activity.
I am looking for a way to display the Activity associated with the intent without having the user to unlock his/her device.
The only solution I have for now is to reimplement what is done by the com.google.android.maps.MapsActivity in my own activity. Unfortunately, this is a lot of work just to mimic what is done with the existing Google Map intent (i.e. displaying places for a given keyword, offering a field to change the keyword, displaying suggestions list, detail view, and direction, etc. all with a good UX).
Any experiences or ideas with such a scenario are welcome.
What I got is that you want to use your app whether screen is lock or unlock like Google Map Navigation, right?
Related
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
I wonder if it possible to retrieve the Google Maps navigation history. In other words, is there a way of retrieving the recent routes taken/searched by the user of the Google Maps app?
Thanks
You can not finish Google Navigation App.
There is only one work around which I found,
Re-start the navigation with the current location, hence the navigation will automatically be finished.
public static void startNavigationIntent(Context activity, String destination)
{
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + destination));
activity.startActivity(intent);
}
And then bring your app to the foreground.
Intent bringToForegroundIntent = new Intent(BackgroundLocationService.this, DashboardActivity.class);
bringToForegroundIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(bringToForegroundIntent);
There is no API available to get information out of the Navigation App. But you can feed some data to Maps to request a route through an Intent / URI.
But I don't think that the Maps app will save the whole route anyway, only the destination. The user selects any saved destination and you can get there from any source.
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.
Hello I'm using built in Google Map to show route to user.
When I click on get route button I have written the following code.
String mapURL="http://maps.google.com/mapssaddr="
+GlobleVeriable.getCurrentLocation().getLatitude()+","+GlobleVeriable.getCurrentLocation().getLongitude()+"&daddr="+restaurant.getLatitude()
+","+restaurant.getLongitude();
Intent i=new Intent("android.intent.action.VIEW",Uri.parse(mapURL));
startActivity(i);
This code Works fine and also displayed route from current location to destination location..
When I come back to my application from Google Maps ,my application start from first.
Can any one suggest me what to do?
Can you please try the code below
String uri="http://maps.google.com/mapssaddr="
+GlobleVeriable.getCurrentLocation().getLatitude()+","+GlobleVeriable.getCurrentLocation().getLongitude()+"&daddr="+restaurant.getLatitude()
+","+restaurant.getLongitude();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(intent);
It's just the average Android behavior. What you can do is to save the current state of the application to some file, right before starting the Google Maps activity. On resume, you can load that file and restore the application manually.
I think it's the only way. It's been a while since I browsed the Android documentation. I do remember something like "... the operating system may terminate your application at any time if inactive, so it's the developer's responsibility to save any user-sensitive information before the application goes inactive".
I'd save within the onPause() method, and load within onResume().
If some other application wants to show something on the map (uses link geo:lat,lng), then before showing the map, it shows 'Maps Applications' list. So, I could choose which map application should be started.
How can I add my own application to this list?
The list here shows the various URL formats used to launch Google apps (including maps). To launch maps you would use:
try {
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0.00,0.00"));
startActivity(myIntent);
} catch (URISyntaxException e) { }
If you want the user to be presented with the option to open your app instead of Google Maps, then you have to register to handle the same Intent in your manifest, maybe something along the lines of this.