Android™
Android™
Get the Plain-Text Body of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.GetPlainTextBody method, which returns the email body having the text/plain content type. It reads the plain-text representation already present in the email object rather than generating one from HTML. This example sets a plain-text body and reads it back.
Background: The plain-text body is the fallback representation of a message — the version shown when HTML can't or shouldn't be rendered, and the form usually preferred for search, indexing, and accessibility.
GetPlainTextBody targets it specifically; if the message contains only HTML, this returns empty (check with HasPlainTextBody), so a robust extractor falls back to GetHtmlBody when needed.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);
// Demonstrates the GetPlainTextBody method, which returns the email body having the
// text/plain content type. It reads the plain-text representation already present in the
// email object.
CkEmail email = new CkEmail();
email.put_Subject("GetPlainTextBody example");
email.SetTextBody("Hello, this is the plain-text body.","text/plain");
// Retrieve the text/plain body.
String plain = email.getPlainTextBody();
Log.i(TAG, plain);
}
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."
}
}