Suppressing the Google Maps intent selection dialog

When i use this code

string url = "somegooglemapsurl.com"; Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url)); startActivity(mapLauncherIntent); 

A selection dialog will appear asking if I want to open this map in the maps application or in the browser. I want the transition from my app activity to Google Maps to be smooth. How can I suppress this dialogue and tell the android to open the card in the card activity?

EDIT: When I get to Google Maps, I want to open a route hint using public transpiration in a specific place. I can do this using google url but url displays select dialog.

+6
source share
3 answers

I have not found the perfect solution, but at least it will open maps with the right choice and public transport. Then all the user needs to do is click the direction button.

It also checks if Google maps are installed and prefers to use it, if so.

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=0,0%20(Imaginary%20Place)&dirflg=r")); if (isAppInstalled("com.google.android.apps.maps")) { intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); } startActivity(intent); 

 // helper function to check if Maps is installed private boolean isAppInstalled(String uri) { PackageManager pm = getApplicationContext().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; } 
+17
source

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; } 
+6
source

First of all, I will simply point out that getting rid of this selection dialog box is not necessarily good. You want to give the user the same choice in how they process the data, as much as possible, this part of the beauty of the Android ecosystem. However, it is unfair to judge without understanding your expression, therefore ...

You can use the geo protocol:

http://developer.android.com/guide/appendix/g-app-intents.html

Instead of passing something like maps.google.com/blablabla , format your URI as follows geo:0,0?q=my+street+address .

Example:

 Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=1111+imaginary+dr")); 
0
source

Source: https://habr.com/ru/post/891892/


All Articles