Android™
Android™
Set a MIME Body from Transfer-Encoded Text
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromEncoded method, which sets the body from already transfer-encoded text. The first argument is the encoding (base64 or quoted-printable) and the second is the encoded text.
Background: Sometimes you already hold content in its encoded form — a Base64 string from a database or another API — and re-decoding just to have Chilkat re-encode it is wasteful. This method stores the encoded text as-is and records the matching transfer encoding, so the body is correct without a needless round trip. Only the standard reversible encodings, Base64 and quoted-printable, are accepted.
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.SetBodyFromEncoded method, which sets the body from already transfer-
// encoded text. The 1st argument is the encoding ("base64" or "quoted-printable") and the 2nd is
// the encoded text.
CkMime mime = new CkMime();
mime.put_ContentType("text/plain");
// The body is provided already Base64-encoded; Chilkat stores it without re-encoding.
String base64Body = "SGVsbG8sIHRoaXMgaXMgdGhlIGJvZHku";
success = mime.SetBodyFromEncoded("base64",base64Body);
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// The decoded body is the original text.
String decoded = mime.getBodyDecoded();
if (mime.get_LastMethodSuccess() == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
Log.i(TAG, decoded);
}
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."
}
}