Sample code for 30+ languages & platforms
Android™

Serialize MIME to a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.

Background: Serializing into a StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.

Chilkat Android™ Downloads

Android™
// 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 Mime.GetMimeSb method, which serializes the complete MIME entity and appends
    //  it to a StringBuilder.  The only argument is the StringBuilder.

    CkMime mime = new CkMime();

    success = mime.SetBodyFromPlainText("Hello, this is the message body.");
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    //  Append the serialized MIME to a StringBuilder.  Existing content is preserved.
    CkStringBuilder sb = new CkStringBuilder();
    success = mime.GetMimeSb(sb);
    if (success == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    Log.i(TAG, sb.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."
  }
}