Android : Android open an external Navigation app

on Thursday, October 9, 2014


I'd like to make an option in my app so the user can open his navigation app in order to navigate to a specific lat,lng coordinates.


After some reading I realized there's no standard URI for navigation, so I can't just do:



private Activity thisActivity;

public void navigate(double destLat, double destLng){
String uri = "geo: "+ destLat + "," + destLng;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(uri));
if(isAppExists(intent))
thisActivity.startActivity(intent);

}

public boolean isAppExists(Intent intent){
PackageManager packageManager = thisActivity.getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
return isIntentSafe;
}


Since by doing this, the app chooser also opens Google Maps (which doesn't support this URI format, for example).


My question is, before implementing a custom dialog to choose only between navigation apps that I support (by writing a special URI for each one of them: for waze using the geo: query, and for google maps, its own format), is there any other way making it with the default app chooser?


Please note that I don't think createChooser method would help me since I can only prevent the selection AFTER the user has selected it, but it would look really bad.


So in the bottom line, what I need to do is to remove apps that I do not support from the app chooser. Do I really have to implement my own custom dialog?


Thanks


0 comments:

Post a Comment