Know if user has Waze installed

Asked

Viewed 124 times

1

I have an application that performs routes between the current position and a certain point.

For this, I call an Activity:

final Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?daddr="+ item.getLatitude() + "," + item.getLongitude()));
     startActivity(intent);

Now let’s implement a feature where the user can select which App he’d like to use: Googlemaps or Waze.

This will be done through a Spinner, and I will only display Waze if it is installed on the user’s Smartphone.

I would like to know how to find out if the user has Waze installed, and how to open it instead of Googlemaps?

2 answers

6


According to this reply (I don’t know if anything has changed in the new Apis, as needed I will adjust the code), you can do this:

private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
    try {
        packageManager.getPackageInfo(packagename, 0);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

I believe the name of the Waze package is com.waze, use like this:

PackageManager pm = context.getPackageManager();

if (isPackageInstalled("com.waze", pm)) {
    //código para waze
} else {
    //talvez um webView para googlemaps
}

You can also test the protocol using Intent:

final String uriwaze = Uri.parse("waze://...");
final String urigooglemaps = Uri.parse("http://maps.google.com/maps?...");

final Intent wazeNavitage = new Intent(android.content.Intent.ACTION_VIEW, uriwaze);

try {
    startActivity(wazeNavitage); //Tenta abrir o Waze
} catch (ActivityNotFoundException e) {
    final Intent googleMapsNavigate = new Intent(android.content.Intent.ACTION_VIEW, urigooglemaps);
    startActivity(intent);
}

I haven’t been able to test it yet, but I believe this is the way

1

You must direct your URI to Waze and if you do not have it you will list the appropriate Apps

Example:

final Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("waze://?ll=" + item.getLatitude() + "," + item.getLongitude() + "&navigate=yes"));
startActivity(intent);
  • So, but in case he’s not installed, there won’t be an option for him

Browser other questions tagged

You are not signed in. Login or sign up in order to post.