Android™
Android™
Set the Content-Disposition of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.SetAttachmentDisposition method, which sets the Content-Disposition value for the attachment at a given zero-based index. The default disposition is attachment. This example changes an attachment's disposition to inline.
Background: The
Content-Disposition header hints how a client should present a part: attachment means "offer it as a download," while inline means "display it within the message" (as an email client does with an embedded image). Setting it lets you control that behavior — though clients ultimately decide how to honor the hint.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 SetAttachmentDisposition method, which sets the Content-Disposition
// value for the attachment at the given zero-based index. The default disposition is
// "attachment".
CkEmail email = new CkEmail();
email.put_Subject("Set attachment disposition");
email.AddStringAttachment("image.txt","(pretend inline content)");
// Set the disposition of the first attachment (index 0) to "inline".
success = email.SetAttachmentDisposition(0,"inline");
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
// The attachment's Content-Disposition is now "inline".
Log.i(TAG, email.getMime());
}
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."
}
}