Android™
Android™
Set the Email Body from a BinData
See more Email Object Examples
Demonstrates the Chilkat Email.SetBodyBd method, which sets the main email body from the binary data in a BinData object. The second argument is the MIME Content-Type, the third is the disposition (may be empty, inline, or attachment), and the fourth is the filename. This example loads HTML content into a BinData and sets it as the body.
Background:
SetBodyBd gives low-level control over the body when you already have its bytes and want to specify the exact Content-Type and MIME disposition yourself. It suits content that is generated or stored as binary — for example an EDI payload, a pre-rendered HTML fragment, or any custom content type — where the convenience of SetHtmlBody / SetTextBody does not apply.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 SetBodyBd method, which sets the main email body from the binary data in
// a BinData object. The second argument is the MIME Content-Type, the third is the
// disposition (may be empty, "inline", or "attachment"), and the fourth is the filename.
CkEmail email = new CkEmail();
email.put_Subject("Body from BinData");
// Load the body content from a file into a BinData object.
CkBinData bd = new CkBinData();
success = bd.LoadFile("qa_data/html/body.html");
if (success == false) {
Log.i(TAG, bd.lastErrorText());
return true;
}
// Set the main body from the binary data as text/html.
success = email.SetBodyBd(bd,"text/html","","");
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, "HasHtmlBody: " + String.valueOf(email.HasHtmlBody()));
// Note: The path "qa_data/html/body.html" is a relative local filesystem path,
// relative to the current working directory of the running application.
}
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."
}
}