我无法在邮件正文中查看图像。它只是像点缀小盒子一样出现。
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..."));
}
});
}
}
答案 0 :(得分: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 );
答案 1 :(得分:1)
我使用SpannableStringBuilder和ImageSpan为文本添加表情符号。