0

So, I have this toHtml function:

  public String toHtml() {
    Uri imageUri = Uri.fromFile(new File("android_asset/" + getFullAssetsFilepath()));
    String html = getString(R.string.email_image, imageUri);
    html += getString(R.string.email_caption, caption);
    return html;
  }

  <string name="email_image">&lt;p>&lt;img src=\"%1$s\" /></string>
  <string name="email_caption">&lt;br/>%1$s&lt;/p></string>

This is the content generated :

<p><img src="file:///android_asset/images/00001.jpg" /><br/>Bird</p>

There are other htmls from other function and together, they are passed into this sendEmail function:

  private void sendEmail(String subject, String content) {
    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_TEXT, 
        Html.fromHtml(content + mContext.getString(R.string.email_generated_by_vancouver_trees)));
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.setType("text/html");
    mContext.startActivity(Intent.createChooser(email, getString(R.string.share)));
  }

The email agent realize it is an image, but all I get in the email is this: [obj] bird

It there another way to generate the src for the assets? I was reading Embedding image in email in Android.

i also tried this

xml

  <string name="email_image">&lt;p>&lt;img src=\"data:image/png;base64,%1$s\" /></string>
  <string name="email_caption">&lt;br/>%1$s&lt;/p></string>

java

  public String toHtml(Context context) {
    try {
      InputStream istr = context.getAssets().open(getFullAssetsFilepath());
      Bitmap bitmap = BitmapFactory.decodeStream(istr);
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
      byte[] byteArray = byteArrayOutputStream .toByteArray();
      String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
      String html = context.getString(R.string.email_image, encoded);
      html += context.getString(R.string.email_caption, caption);
      return html;
    } catch (IOException e) {
    }
    return "";
  }

But I still end up with [obj] box

In fact, I have tried src="[static image html]" and i still get [obj]

Community
  • 1
  • 1
Joanne Chow
  • 1,018
  • 10
  • 8

0 Answers0