The autoLink attribute of TextView provides us with great convenience. When there is a URL, email address, or phone number in the text, it makes it easy for us to call and send emails, but there are also some problems, for example, if you set autoLink to include the email attribute, you can call the email client to send an email when you click an email address in the text. However, if no email client is available in the current system, the program will be directly suspended.
Through reading the Log, we can find that the system throws the ActivityNotFoundException Exception, and the getMessage of Exception contains the "mailto: xxxx@xxx.xxx", the first reaction was to set the Thread. uncaughtExceptionHandler: If the exception type is ActivityNotFoundException and the Error Message contains "mailto", the uncaughtException function is directly returned. If you try it, the program does not get down and you are in the middle of the process, but then I clicked on the screen, and ANR will be ready in five seconds. Well, this method won't work.
I also thought that when I click the link, I will call the mail client to send an email. There must be a startActivity call. So I will reload the startActivity function of the Activity and print the intent parameter content (directly toString () on the line), found in the Intent content is ACTIVION_VIEW, and extra data: mailto: xxxx@xxx.xxx, therefore, you can use the intent information to determine whether the email client can process the request if it contains the mailto text, if not, block the startActivity event.
(intent.toString().indexOf("mailto") != -1) { PackageManager pm = List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0 (activities == || activities.size() == 0
The code is like this. It is very simple. Three methods are mentioned. The first and second methods use PackageManager to determine whether a component can process the Intent request. If not, startActivity is directly returned, what do you want to do before returning? The third method is to use Intent. createChoose manually pops up a selector. This method can't be used in the past. This time I tried it. Is it wrong? Use the first two methods.
It's not just an email. If you want to use the following code to jump to the app marketplace and let users score your app
Intent intent = "market://details?id=" +