Android™
Android™
Get the HTML Body into a StringBuilder
See more Email Object Examples
Demonstrates the Chilkat Email.GetHtmlBodySb method, which returns the text/html body into a StringBuilder. If the first argument is true, the related images found in the MIME are inlined as base64 data URLs directly within the returned HTML. This example retrieves the HTML body without inlining images.
Background: The inline-images option is useful for producing self-contained HTML that displays correctly in a browser or web view without needing the separate related parts — each
cid: reference is replaced by a data: URL holding the image bytes. Be aware this can substantially enlarge the HTML, since base64 embedding adds roughly a third to each image's size. Writing into a StringBuilder is efficient for that potentially large output.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Demonstrates the GetHtmlBodySb method, which returns the text/html body into a
// StringBuilder. If the first argument is true, related images found in the MIME are
// inlined as base64 data URLs directly within the returned HTML.
CkEmail email = new CkEmail();
email.put_Subject("GetHtmlBodySb example");
email.SetHtmlBody("<html><body><b>Hello in HTML.</b></body></html>");
// Get the HTML body into a StringBuilder (false = do not inline related images).
CkStringBuilder sbHtml = new CkStringBuilder();
success = email.GetHtmlBodySb(false,sbHtml);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, sbHtml.getAsString());
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}