How to embed a URL in an Android email address

From my application, I want to share some details by email and on all other sites. The following is my email open code

private void email() 
{
  Intent i = new Intent(Intent.ACTION_SEND);  
  i.setType("message/rfc822") ;
  i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});  
  i.putExtra(Intent.EXTRA_SUBJECT,i0+" hiiiiiiiiii");  
  i.putExtra(Intent.EXTRA_TEXT,**sharetext**);  
  startActivity(Intent.createChooser(i, "Select application"));
}

Below is my general text

"hello friends please visit my website for http://www.xxxxxxxx.com/apply "

Now I want the URL of my shared text to appear in a blue line, so when a user clicks on it, I want to open a web page.

But in my application, the url seems ok. How to do it....

+2
source share
1 answer

SpannableStringBuilder URL. :

private void email() 
{
    String url = "http://www.xxxxxxxx.com/apply";

    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append("hi friends please visit my website for");
    int start = builder.length();
    builder.append(url);
    int end = builder.length();

    builder.setSpan(new URLSpan(url), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    Intent i = new Intent(Intent.ACTION_SEND);  
    i.setType("message/rfc822") ;
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});  
    i.putExtra(Intent.EXTRA_SUBJECT,"hiiiiiiiiii");  
    i.putExtra(Intent.EXTRA_TEXT, builder);  
    startActivity(Intent.createChooser(i, "Select application"));
}

enter image description here

+12

All Articles