1

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>
user25
  • 2,873
  • 2
  • 30
  • 66

2 Answers2

0

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();
}
  • I don't use `startActivity`, check https://stackoverflow.com/questions/4682859/textview-to-send-email-when-clicked?noredirect=1&lq=1 – user25 Mar 04 '19 at 12:20
0

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();
} 
Studio2bDesigns
  • 578
  • 5
  • 12