2017-08-14 87 views
3

我有一段代碼可以識別電子郵件,但不會。我認爲這是因爲電子郵件地址(@符號前的部分)的'開始'部分只有兩個字符。有誰知道如何解決這一問題?我試過使用android:autoLink="all",但那也沒有效果。AutoLink不會將電子郵件識別爲電子郵件

這裏是我的電子郵件代碼:

<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" /> 

所有這些都被識別爲電子郵件,除了第二封電子郵件([email protected])。我做了一些研究,並且在研究linkify類時,android聲明「指示電子郵件地址的Bit字段應該在採用選項掩碼的方法中匹配; Constant Value:2(0x00000002)。」

我對編程相當陌生,我不明白這是什麼意思,但我猜它與我的問題有關。

結論:「[email protected]」不會被識別爲電子郵件,因爲@符號前只有兩個字符,並且如何使所述電子郵件被識別爲電子郵件並直接發送到gmail應用程序。

謝謝!

回答

0

有人回答了這個問題,但是在我試用它的時候刪除了它,它工作正常!

這是建議的解決方案:

TextView feedback = (TextView) findViewById(R.id.textView); 
    feedback.setText(Html.fromHtml("<a href=\"mailto:[email protected]\">Wanted Text</a>")); 
    feedback.setMovementMethod(LinkMovementMethod.getInstance()); 

哪裏textView是要鏈接的TextView的id,[email protected]是所需的電子郵件收件人,Wanted Text是要顯示給用戶的文本。

感謝誰給了我這個解決方案!