Skip to content

Instantly share code, notes, and snippets.

@josejuansanchez
Created December 10, 2014 23:41
Show Gist options
  • Save josejuansanchez/16d580c2e8ce0bf34706 to your computer and use it in GitHub Desktop.
Save josejuansanchez/16d580c2e8ce0bf34706 to your computer and use it in GitHub Desktop.
Comprueba si hay algún Activity que sea capaz de manejar un determinado Intent
public static boolean isAvailable(Context ctx, Intent intent) {
final PackageManager mgr = ctx.getPackageManager();
List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
public void openGoogleMaps(View v) {
Uri geoLocation = Uri.parse("geo:36.782085,-2.815337?q=36.782085,-2.815337");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (isAvailable(this, intent)) {
startActivity(intent);
} else {
Toast.makeText(this, "El intent no se puede lanzar", Toast.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment