public static void startGoogleDirections(Activity activity, String saddr,
String daddr) {
Uri.Builder builder = new Uri.Builder();
builder.encodedPath("http://maps.google.com/maps")
.appendQueryParameter("f", "d")
.appendQueryParameter("hl", "en");
// from can be null
if (!isEmpty(saddr)) {
builder.appendQueryParameter("saddr", saddr);
}
// to can be null
if (!isEmpty(daddr)) {
builder.appendQueryParameter("daddr", daddr);
}
Uri uri = Uri.parse(builder.build().toString());
Intent i = new Intent(Intent.ACTION_VIEW, uri);
if (i != null) {
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
& Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
activity.startActivityForResult(i,0);
}
}