Search code examples
androidxmlemaillinkify

AutoLink won't recognize an email as an email


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: \[email protected]"
    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: \[email protected]"
    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: \[email protected]"
    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: \[email protected]"
    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 ([email protected]). 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 "[email protected]" 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!


Solution

  • 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:[email protected]\">Wanted Text</a>"));
        feedback.setMovementMethod(LinkMovementMethod.getInstance());
    

    Where textView is the id of the textView you want to link, [email protected] 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!