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.
我有一段应该识别电子邮件的代码,但没有。我认为这是因为电子邮件地址的“开始”部分(@符号前面的部分)只有两个字符。有谁知道如何解决这一问题?我尝试使用android:autoLink =“all”,但这也不起作用。
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)."
除第二封电子邮件(hr@opsconsulting.com)外,所有这些都被识别为电子邮件。我做了一些研究,并在研究linkify类时,android声明“比特字段指示电子邮件地址应该在采用选项掩码的方法中匹配;常量值: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.
总之:“hr@opsconsulting.com”不会被识别为电子邮件,因为@符号前面只有两个字符,如何将所述电子邮件识别为电子邮件并直接发送到gmail应用程序。
Thanks!
谢谢!
2 个解决方案
#1
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.
如果textView是您要链接的textView的id,则ex@example.com是所需的电子邮件收件人,而Wanted Text是您要向用户显示的文本。
Thanks to whoever it was that gave me this solution!
感谢无论是谁给了我这个解决方案!
#2
#1
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.
如果textView是您要链接的textView的id,则ex@example.com是所需的电子邮件收件人,而Wanted Text是您要向用户显示的文本。
Thanks to whoever it was that gave me this solution!
感谢无论是谁给了我这个解决方案!