Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 }

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.

like image 546
user1002448 Avatar asked Apr 18 '18 11:04

user1002448


1 Answers

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);
like image 123
Anton Kazakov Avatar answered Nov 14 '22 21:11

Anton Kazakov