How to start activity in map view by default? - android

i am developing android app to get direction between 2 location, as below
Intent intent = new Intent(android.content.Intent.ACTION_VIEW;
Uri.parse("http://maps.google.com/maps?saddr=12.84281852,80.22529753&daddr=13.00355419,80.200881958"));
startActivity(intent);
Running this application, it is prompting me to choose one among 1) Browser 2) Map
How to open it in map by default in coding??

I think if you call setPackage() with 'com.google.android.apps.maps' it should launch Google maps.
This worked fine for me:
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"));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

Related

How to stop launching activity multiple times

I'm launching Google Maps in Android from a particular view in my app layout like this:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
view.getContext().startActivity(mapIntent);
Once I'm done with the maps and return to my app, the maps app is being launched again when I click anywhere (not just that particular view) on my app.
How do I stop this from happening?
I need maps to launch only when a particular view is displayed.
Try to call finish(); and return(); after you are starting the intent
something like this
Intent mapIntent = new Intent(Intent.ACTION.VIEW,loaction);
view.getContext().startActivity(mapIntent);
finish();
return;

Android : Recreate Map Toolbar : Open In Google Maps

So I am building a map that shows locations (markers). I don't want to use the Map ToolBar (which has directions and open in Google Maps button) however I do want to make my own button that opens in GoogleMaps with directions to that marker.
try this:
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);
Or if not working try this according to this link https://developers.google.com/maps/documentation/urls/guide:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393"));
startActivity(intent);

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);

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.

Coming back from Android Market does not show app again

I am starting market intent to go my app. It starts well and also showing my app. But problem with this is when pressing back, it is not coming to my my app again. Also when pressing home in market, again launch app, it shows market page instead of app.
Here is the code which i am using.
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id=" + AndroidUtils.getPackageName()));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(marketIntent);
Thanks in advance!
use
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id=" + AndroidUtils.getPackageName()));
startActivity(marketIntent);
don't use the flags because the activities are cleared when u use these flags

Categories

Resources