Created
December 10, 2014 23:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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