Android™
Android™
Append a Part to a Multipart MIME Entity
See more MIME Examples
Demonstrates the Chilkat Mime.AppendPart method, which appends a copy of another Mime as the last direct child. The only argument is the source Mime. Chilkat copies it, so later changes to the source do not affect the appended part.
Background: This is the general way to build up a multipart entity from parts you construct yourself — a text body, an HTML body, a nested multipart. Because it appends a copy, you can reuse and modify the source object afterward, or append it more than once, without surprises. For attaching a file directly,
AppendPartFromFile is more convenient.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.AppendPart method, which appends a copy of another Mime as the last direct
// child. The only argument is the Mime to append. Chilkat copies it, so later changes to the
// source do not affect the appended part.
CkMime mime = new CkMime();
success = mime.NewMultipartMixed();
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// Build a part and append a copy of it.
CkMime part = new CkMime();
success = part.SetBodyFromPlainText("This is an appended part.");
if (success == false) {
Log.i(TAG, part.lastErrorText());
return;
}
success = mime.AppendPart(part);
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
Log.i(TAG, "Number of parts: " + String.valueOf(mime.get_NumParts()));
}
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."
}
}