Know if user has Waze installed

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 we will implement a feature where the user can select which App he would like to use: GoogleMaps or Waze .

This will be done through 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 do I open it instead of GoogleMaps?

    
asked by anonymous 03.03.2017 / 21:14

2 answers

6

As this response (I do not know if anything has changed in the new APIs, as I will adjust the code), you you can do this:

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

I think the package name of waze is com.waze , so use:

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 have not been able to test it yet, but I believe this is the way

    
03.03.2017 / 21:46
1

You should direct your Direct 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);
    
03.03.2017 / 21:21