mailto crashes an app if user doesn't have mail app

问题: Is it possible to catch this exception when using mailto: in TextView's text? Fatal Exception: android.content.ActivityNotFoundException No Activity found to handle I...

问题:

Is it possible to catch this exception when using mailto: in TextView's text?

Fatal Exception: android.content.ActivityNotFoundException No Activity found to handle Intent { act=android.intent.action.VIEW dat=mailto:xxxxxxx@xxxxx.xxx (has extras) } android.widget.TextView.onTouchEvent

<string name="about_text"><![CDATA[
Support: <a href="mailto:test@gmail.com">test@gmail.com</a>
]]></string>

回答1:

you can handle this error while try to execute it like this:

try {
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    Toast.makeText(mContext, "your error message" , Toast.LENGTH_SHORT).show();
}

回答2:

You can still use this to catch the exception, regardless of how it gets thrown, whether through startActivity or otherwise..

try {
    //  Your Code Here
} catch (ActivityNotFoundException e) {
    Toast.makeText(this, "Mail client not found", Toast.LENGTH_LONG).show();
} 
  • 发表于 2019-03-06 10:35
  • 阅读 ( 743 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除