开发者

how to insert an URL in android email

开发者 https://www.devze.com 2023-03-13 04:21 出处:网络
From my app i want to share some detail via email and all other sites. Following is my code to open 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

精彩评论

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