开发者

how to insert an URL in android email

From my app i want to share some detail via email and all other sites. Following is my code to open email

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.pu开发者_运维百科tExtra(Intent.EXTRA_TEXT,**sharetext**);  
  startActivity(Intent.createChooser(i, "Select application"));
}

Following is my sharetext

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

Now i want the url in my share text to be viewed in a blue line, so that when the user clicks it i want to open the webpage.

But in my app the url seems to be normal one. How to do this....


You can use SpannableStringBuilder to build text with embedded url link. Here is an example:

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"));
}

how to insert an URL in android email

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜