Skip to content

Instantly share code, notes, and snippets.

@angeldevil
Last active January 1, 2016 00:09
Show Gist options
  • Save angeldevil/8064943 to your computer and use it in GitHub Desktop.
Save angeldevil/8064943 to your computer and use it in GitHub Desktop.
Resolve issue that app crashes when clicks a TextView with autoLink be set to email or all but the system has no email client.
@Override
public void startActivity(Intent intent) {
if (intent.toString().indexOf("mailto") != -1) { // Any way to judge that this is to sead an email
PackageManager pm = getPackageManager();
// The first Method
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities == null || activities.size() == 0) {
// Do anything you like, or just return
return;
}
// Another method
// ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
// if (resolveInfo == null)
// Yet another metod
// Intent.createChooser(intent, "Choose email client");
}
super.startActivity(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment