No Activity found to handle Intent { act=android.intent.action.VIEW dat=google.navigation:q=17.399986,78.483137 pkg=com.google.android.apps.maps }
Asked Answered
F

1

5

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.

Fluellen answered 18/4, 2018 at 11:25 Comment(5)
you say in certain cases, do you mean different devices or different lat/lon values?Halter
Its random. Can't determine if its for certain lat lon or for devices. Its coming for different devicesFluellen
You are forcing the com.google.android.apps.maps package, so it might be because the user does not have this app installed, or the link you're generating is broken and can not be understood by google maps (or any other apps on the device)Halter
So if maps is not installed how do we handle the intentFluellen
Can't you open the map through the users' web browser?Halter
M
7

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);
Moneybag answered 18/4, 2018 at 11:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.