Android™
Android™
Remove All Related Items from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.DropRelatedItems method, which removes all related items (embedded images, style sheets, and similar resources) from the email at once. This example adds two related items and then drops them all, printing the count before and after.
Background: Related items are the inline resources bundled with an HTML body inside a
multipart/related enclosure. Dropping them all in one call is handy when you want to keep the HTML text but discard its embedded media — for instance, converting a rich message to a lightweight, text-focused version, or clearing inline images before re-adding fresh ones. To remove a single item instead, use DropRelatedItem with its index.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);
// Demonstrates the DropRelatedItems method, which removes all related items (embedded
// images, style sheets, etc.) from the email at once.
CkEmail email = new CkEmail();
// Set an HTML body that references two related items by name (Content-Location).
email.SetHtmlBody("<html><head><link rel=\"stylesheet\" href=\"styles.css\"/></head><body><img src=\"logo.png\"/></body></html>");
// Add two related items.
email.AddRelatedString2("styles.css","body { color: navy; }","utf-8");
email.AddRelatedString2("logo.png","(pretend image data)","utf-8");
Log.i(TAG, "NumRelatedItems before = " + String.valueOf(email.get_NumRelatedItems()));
// Remove all related items.
email.DropRelatedItems();
Log.i(TAG, "NumRelatedItems after = " + String.valueOf(email.get_NumRelatedItems()));
}
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."
}
}