AutoLink won't recognize an email as an email

3

I have a piece of code that should recognize an email, but doesn't. I think it is because the 'beginning' part of the email address (the part before the @ sign) only has two characters. Does anyone know how to fix this? I tried using android:autoLink="all" but that didn't work either.

Here is my code for the emails:

<TextView
    android:id="@+id/textView7"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="General Inquiries: \ncontact@opsconsulting.com"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView4"
    android:layout_marginLeft="24dp"
    app:layout_constraintLeft_toLeftOf="parent"
    android:textAppearance="@style/Body"
    android:autoLink="email"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHorizontal_bias="0.0" />

<TextView
    android:id="@+id/textView10"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Human Resources: \nhr@opsconsulting.com"
    android:textAppearance="@style/Body"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView7"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/textView7"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:id="@+id/textView11"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Recruiting: \nrecruiting@opsconsulting.com"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView10"
    android:textAppearance="@style/Body"
    android:autoLink="email"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/textView10"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:id="@+id/textView12"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Legal and Contacts: \nlegal@opsconsulting.com"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView11"
    android:textAppearance="@style/Body"
    android:autoLink="email"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/textView11"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHorizontal_bias="0.0" />

<TextView
    android:id="@+id/websitegoto"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="www.opsconsulting.com"
    android:autoLink="web"
    android:layout_marginTop="10dp"
    app:layout_constraintTop_toBottomOf="@+id/imageView6"
    android:layout_marginBottom="16dp"
    app:layout_constraintBottom_toTopOf="@+id/textView4"
    app:layout_constraintVertical_bias="0.0"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="@+id/imageView6"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="@+id/imageView6"
    android:textAppearance="@style/Body" />

All of them are being recognized as emails, except for the second email (hr@opsconsulting.com). I did some research and in looking into the linkify class, android states that the "Bit field indicating that email addresses should be matched in methods that take an options mask; Constant Value: 2 (0x00000002)."

I am fairly new to programming, and I don't understand what this means, but I'm guessing it has something to do with my problem.

In conclusion: will "hr@opsconsulting.com" not be recognized as an email because there are only two characters before the @ sign, and how do I make said email be recognized as an email and direct to the gmail app.

Thanks!

android
xml
email
linkify
asked on Stack Overflow Aug 14, 2017 by Mairead

2 Answers

0

Someone answered this, but then deleted it while I was trying it out, and it worked!

Here was the suggested solution:

    TextView feedback = (TextView) findViewById(R.id.textView);
    feedback.setText(Html.fromHtml("<a href=\"mailto:ex@example.com\">Wanted Text</a>"));
    feedback.setMovementMethod(LinkMovementMethod.getInstance());

Where textView is the id of the textView you want to link, ex@example.com is the desired email recipient, and Wanted Text is the text you want to appear to the user.

Thanks to whoever it was that gave me this solution!

answered on Stack Overflow Aug 14, 2017 by Mairead
0

This Html.fromHtml("<a href=\"mailto:ex@example.com\">Wanted Text</a>") didn't work. Not sure whether this is the correct way to write or not : <a href=\"mailto:ex@example.com\">Wanted Text</a>

answered on Stack Overflow Jun 26, 2018 by user1182217

User contributions licensed under CC BY-SA 3.0