Sample code for 30+ languages & platforms
Android™

Serialize MIME to a String

See more MIME Examples

Demonstrates the Chilkat Mime.GetMime method, which serializes and returns the complete MIME entity — headers, body, multipart boundaries, and all descendants — as a string. It takes no arguments.

Background: This produces the finished MIME text ready to send, store, or hand to another component — the inverse of loading. The whole tree is emitted, including generated multipart boundaries. Because it returns a string, it is best for text-safe content; when the body may contain raw binary bytes, serialize with GetMimeBd to a BinData instead so nothing is altered.

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.GetMime method, which serializes and returns the complete MIME entity
    //  (headers, body, multipart boundaries, and all descendants) as a string.  It takes no
    //  arguments.

    CkMime mime = new CkMime();

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

    //  Serialize it to a string.
    String mimeText = mime.getMime();
    if (mime.get_LastMethodSuccess() == false) {
        Log.i(TAG, mime.lastErrorText());
        return;
        }

    Log.i(TAG, mimeText);

  }

  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."
  }
}