Android™
Android™
Set a MIME Body from Plain Text
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromPlainText method, which sets the body as plain text. The only argument is the text. For ASCII input Chilkat uses text/plain with 7bit encoding; for non-ASCII it selects an appropriate charset and encoding.
Background: This is the simplest way to give a MIME entity a text body — Chilkat picks a sensible
Content-Type and transfer encoding for you based on the content. Plain ASCII stays as 7bit with no charset, while text containing accented or non-Latin characters gets a charset (typically UTF-8) and a suitable encoding so it survives transmission intact. It is the text counterpart to SetBodyFromHtml and SetBodyFromXml.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 Mime.SetBodyFromPlainText method, which sets the body as plain text. The only
// argument is the text. For ASCII, Chilkat sets Content-Type: text/plain and a 7bit transfer
// encoding; for non-ASCII it selects an appropriate charset and encoding.
CkMime mime = new CkMime();
success = mime.SetBodyFromPlainText("Hello, this is a plain-text message body.");
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
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."
}
}