I am trying to launch maps using the following code.
public static void navigate(Context context, double lat, double lon) {
String locationQuery = lat + "," + lon;
Uri gmmIntentUri = Uri.parse("google.navigation:q=" + locationQuery);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
context.startActivity(mapIntent);
}
But in certain cases I am getting no activity found to handle intent crash. What I am doing wrong here.
I think you should check is this package installed like this
private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packagename, 0);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
And if it isn't then open web version. Or check out Google Maps docs. AFAIK there is a way Maps can handle it.
Or you can check is app available this way:
if (mapIntent.resolveActivity(getPackageManager()) != null) {
...
}
If App is not installed you can:
1.Redirect user to Google Play
2.Open map in browser.
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With