There is no problem in the system where the email client fails to set autoLink = email.

Source: Internet
Author: User

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=" +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.