I am developing a geo located based app, and I have an option : "Show me the way" that should show the map and how to get there, so far is working with google maps, and also with Waze, the Uber app is showing in the App selector to open the action (Intent) that I'm throwing from the app, but it does not work with the data is receivng, so What additional data should I send? I was reading the Uber official documentation but it's more for web and URL based calls and I haven't found an example with the "geo" tag Intent that I'm using and works for other apps.
The code I am using to throw the Intent is this:
case R.id.menu_ride:
{
String uri = "geo: "+newPlace.getLatitude()+","+newPlace.getLongitude();
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
return true;
}
I don't know if it is the right way to do it but this is the way I am using it and it's working on Google Maps, Uber and Waze with no problems:
case R.id.menu_ride:
{
String uri = "geo: "+newPlace.getLatitude()+","+newPlace.getLongitude() +
"?q="+newPlace.getLatitude()+","+newPlace.getLongitude() ;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
return true;
}
Seeems like you had to add the GET parameter "q" for the query.
Related
Is it possible to launch Huawei Petal Maps with navigation from point A to point B using intent just like in google maps? If yes, how?
Yes, you can use an intent to launch the Petal Map app, and then use navigation functions in the app.
Deep link example:
mapapp://navigation?saddr=xxx&daddr=xxx&language=xx&type=xxx
mapapp://navigation?saddr=home&daddr=company&language=en&type=drive
mapapp://navigation?type=exit
To use this function, you need to set uriString to the following:
"mapapp://navigation?saddr=25.102916,55.165363&daddr=25.164610000000,55.228869000000&language=en&type=drive"
Sample code after modification:
String uriString = "mapapp://navigation?saddr=25.102916,55.165363&daddr=25.164610000000,55.228869000000&language=en&type=drive";
Uri content_url = Uri.parse(uriString);
Intent intent = new Intent(Intent.ACTION_VIEW, content_url);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
For more details, see docs.
As it would seem from this link, India is currently not among the supported regions for Huawei Petal Map. Currently, you would not be able to use it for navigation.
I am creating an app where it requires opening google maps to navigate to a place in walking mode and to set source/from location to current location.
Here is the code I use.
String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
How do I set "From location" to "current location"??
Thanks.
I would suggest using a Google Maps URLs instead of the link you provided in the example. The Google Maps URLs is an official and recommended way to launch Google Maps app on mobile devices and web browsers.
Please note that if you omit the origin parameter in the Google Maps URLs, the API will use your current location if available
origin: Defines the starting point from which to display directions. Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin. The value can be either a place name, address, or comma-separated latitude/longitude coordinates. A string should be URL-escaped.
So, you should rewrite your code as
String url = "https://www.google.com/maps/dir/?api=1&destination=" + destination + "&travelmode=walking&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
I hope this helps!
I'm creating this question after finding the answer, I was not sure about the etiquette, but it seems to be OK (plus, I see now there's a built-in option).
The problem was as described in the title, we created an intent chooser using code that resembles this:
String url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes";
Intent intentWaze = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
Intent intentGoogleNav = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));
String title = context.getString(R.string.title);
Intent chooserIntent = Intent.createChooser(intentGoogleNav, title);
Intent[] arr = new Intent[1];
arr[0] = intentWaze;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
context.startActivity(chooserIntent);
And got two Waze icons and one Google Maps icon; and worse, one of the Waze icons did not start the navigation (only open the app).
We could not use the geo: intent because we need to control the intents shown (we don't want to show both intents at all times) and the navigation type in Google Maps (for example: &mode=w).
After some time I used the solution found here, and there was only one icon that was working properly. As I wrote in the question, I could not use this solution because it lacks the flexibility I needed, so after looking at the code I saw that what was missing was this:
intentWaze.setPackage("com.waze");
// and more importantly, this:
intentGoogleNav.setPackage("com.google.android.apps.maps");
It seems that Waze is listening to the Google Maps intent (and does not work well with it), and that's why there were two icons.
From my app, I currently invoke google map using this:
Uri uri = Uri.parse("geo:" + "45.420833" + "," + "-75.69?z=13");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
I need to turn on the traffic layer upon launching the intent.
I couldn't find any simple way to do so online. I couldn't find an extra parameter to do so either :(
Any idea?
Altough I have not tried it yet, this might work for you if you are using a mapView within the app:
mapView.setTraffic(true);
I need to turn on the traffic layer upon launching the intent.
You will have to embed MapView for that, AFAIK.
I am building many apps for Android and wish to have a menu button in the apps that basically opens a list of my other apps in the Android Market.
Is there a way to create an intent and have the Android market pop up with a search (of my company) in the market so users can buy other apps?
ian
Even better to use "market://details" instead of "market://search":
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
Then it opens directly the details page of the app. With search it shows a single search result and the user has to do an additional click to get to the detail page.
Yes, there is a documented Intent syntax for that (http://market.android.com/search?q=pub:<Developer Name> or market://search?q=pub:<Developer Name>).
The intent action would be view, and uri the market url/uri.
Like this:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:<developer name>") ) );
Another way is to launch a URL Intent with your application's package name in it.
User will get popup with list of installed Browsers + Play Store app in which he can view your target app.
String appPackageName = "com.example.android";
String url = "https://play.google.com/store/apps/details?id=" + appPackageName;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
Above code is tested and works as expected on Play Store version 4.1.6
On my real devices Sony Xperia Pro and PocketBook tablet, even when you put a link to play web store e.g. https://play.google.com/store/apps/details?id=com.estrongs.android.pop
It will ask if you want to open it in the default browser or in the Play market.
If you select Play market - application is shown as expected.
Did not test it with intent, tested with Autolink from TextView.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.adfree:
final String appPackageName = "com.zooohooo.noads"; // Can also use getPackageName(), as below
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
return true;
case R.id.rate:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
return true;
}
return super.onOptionsItemSelected(item);
}