0

I have an application based on google maps, in which I am opening route planner using intent. But, when application starts, it prompts dialog box to user with option of default browser and maps. But, I want that when application starts, it should open in maps by default. Below I am posting my code.

public class RoutePlannerActivity extends MapActivity {
public static final String TAG = "Route planner";
MapView mapView;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mapView = (MapView)findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);
    Log.d(TAG, "onCreate");
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
            Uri.parse("http://maps.google.com/maps?saddr=28.6667,77.2167&daddr=28.5700,77.3200")); 
    startActivity(intent);
}//onCreate

protected boolean isRouteDisplayed() {
    Log.d(TAG, "Route displayed");
    return true;
}//isRouteDisplayed
}//class
Nitish
  • 3,097
  • 13
  • 45
  • 80

2 Answers2

2

If you want to get rid of the dialog you can give the intent a hint as to which package you want to use. Before the startActivity() add this:
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
Credits to this previous post. I suggest searching before posting.

Community
  • 1
  • 1
Urban
  • 2,201
  • 24
  • 52
1

try this code for rid of the dialog..

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?" + "saddr=23.0286423,72.5580967&daddr=23.0559485,72.5423041"));
        intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
        startActivity(intent);
Niranj Patel
  • 32,980
  • 10
  • 97
  • 133