2011-08-09 38 views
0

我無法在郵件正文中查看圖像。它只是出現像點綴的小盒子。如何在撰寫郵件正文中用圖像發送郵件文本

setContentView(R.layout.mailshare); 
    send = (Button)findViewById(R.id.button1); 
    address = (EditText)findViewById(R.id.emailaddress); 
    //subject = (EditText)findViewById(R.id.emailsubject); 
    // emailtext = (EditText)findViewById(R.id.emailtext); 
    Bundle extras = getIntent().getExtras(); 
    if(extras != null) { 
     String emailtitle = extras.getString(TEXT_DATA); 
     if(emailtitle != null) { 
      subject = (EditText)findViewById(R.id.emailsubject); 
      if(subject != null) { 
       subject.setText(emailtitle); 
      } 
     } 
    } 

    Bundle mailmsg = getIntent().getExtras(); 
    if(mailmsg != null) { 
     String bodytext = mailmsg.getString(BODY_TEXT); 
     if(bodytext != null) { 
       emailtext = (EditText)findViewById(R.id.emailtext); 
      if(subject != null) { 
       emailtext.setText(bodytext); 
      } 
     } 
    } 

    send.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      [enter link description here][2]//     
      // TODO Auto-generated method stub 
      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()}); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText()); 
      emailIntent.setType("image/png"); 

      Spanned html =Html.fromHtml("<html><body> <img src='http://www.example.com/logo.png'> </body></html>", 

        new ImageGetter() { 

        InputStream s; 
        public Drawable getDrawable(String url) { 

         try { 
         s = (InputStream) (new URL(url)).getContent(); 
         } catch (MalformedURLException e) { 

         e.printStackTrace(); 
         } catch (IOException e) { 

        e.printStackTrace(); 
        } 
        Drawable d = Drawable.createFromStream(s, null); 
        // Log.debug(this, "Got image: " + d.getClass() + ", " + d.getIntrinsicWidth() + "x" + d.getIntrinsicHeight()); 
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
        return d; 
        }},null); 
       // emailIntent.putExtra(emailIntent.EXTRA_TEXT, html); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, html); 
        startActivity(Intent.createChooser(emailIntent, "Send mail...")); 



     } 
    }); 

} 

}

回答

1

我用SpannableStringBuilder和ImageSpan添加表情符號的文本。

+0

Vikky嗨,但我需要在郵件正文中的文本的末尾附加標誌。是否有任何方法 – user537771

+0

謝謝你vikky,我用上面的代碼作爲U表示(Span圖像),但無法查看 – user537771

2

嗨,我沒有通過下面的代碼...

SpannableStringBuilder builder = new SpannableStringBuilder(text); 
Matcher matcher = mPattern.matcher(text); 
while (matcher.find()) { 
      int resId = mSmileyToRes.get(matcher.group()); 
      builder.setSpan(new ImageSpan(mContext, resId), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
} 



(Editable) editMessageText.setText (builder); 
+0

此代碼用於追加微笑文本但不是圖像(.png,.jpeg),可以重寫以上代碼在郵件正文中追加圖像 – user537771

相關問題