如果手机未安装邮件客户端,当用户点击TextView上的邮件链接时,程序就会崩溃,这个问题可以使用如下方法解决:
在包含邮件链接的TextView所在的Activity中重载startActivity(...)方法,具体如下:
@Override
public void startActivity(Intent intent) {
try {
super.startActivity(intent);
} catch (ActivityNotFoundException e) {
/*
* Probably an no email client broken. This is not perfect,
* but better than crashing the whole application.
*/
Util.longToast(this, R.string.toast_no_email_client);
//super.startActivity(Intent.createChooser(intent, null));
}
}
捕获异常后,提示用户未安装邮件客户端即可。