In my app I have a button, which opens a Google map with sent coordinates.
final ImageView view = findViewById(R.id.navigate);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr="+gps1+","+gps2));
startActivity(intent);
}
});
This is working fine, but I want to offer to the user all navigation apps that he has in his device after button click.
So not to automatically open Google Maps, but let the user choose which app to use.
I found this solution, but this is only for Google maps and Waze. As I can't know which and how many navigation apps the user has on his device, I can't hardcode all existing navigation apps.
String url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes";
Intent intentWaze.setPackage("com.waze");
Intent intentWaze = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
Intent intentGoogleNav.setPackage("com.google.android.apps.maps");
Intent intentGoogleNav = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));
String title = context.getString(R.string.title);
Intent chooserIntent = Intent.createChooser(intentGoogleNav, title);
Intent[] arr = new Intent[1];
arr[0] = intentWaze;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
context.startActivity(chooserIntent);
So is there any solution, which can offer all navigation apps that the user has?
For example for sharing function it works like this:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
infox);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share)));
This will show many apps with sharing possibility. How to do the same for apps with map?
EDIT: I added this to google and waze code, so now I have listed in chooser: Google map, Waze and an unknown android icon, when I click it, it shows all navigation apps on my device! However only if I click that unnamed icon and it only opens those maps without navigation.
String urlx = "geo:" + gps1 + ", " + gps2;
Intent intentOther = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
I need to show all those app immediately after button click.