Android™
Android™
Set a MIME Body, Preserving Content Headers
See more MIME Examples
Demonstrates the Chilkat Mime.SetBody method, which sets the current part's body while preserving the existing content headers (Content-Type, charset, Content-Transfer-Encoding). The only argument is the body text; it is a void method.
Background: Unlike the
SetBodyFrom... methods, which set both the content and the headers that describe it, SetBody replaces only the body text and leaves the existing Content-Type and encoding in place. That is what you want when the media type is already correct and you simply need to swap in new content — updating a templated part, for instance — without re-declaring its type.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.SetBody method, which sets the current part's body while preserving the
// existing content headers (Content-Type, charset, Content-Transfer-Encoding). The only argument
// is the body text. It is a void method.
CkMime mime = new CkMime();
// Establish the content headers first.
success = mime.SetBodyFromPlainText("initial");
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// Replace just the body text, keeping the existing Content-Type and encoding.
mime.SetBody("This is the replacement body text.");
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."
}
}