Sample code for 30+ languages & platforms
Android™

Exclude Resources Matching a Pattern

See more MHT / HTML Email Examples

Demonstrates Mht.ExcludeImagesMatching, which adds an exclusion pattern used while gathering embeddable resources, so matching resources are omitted from the archive.

Background. Despite the method name, the test applies to embeddable resources generally, not only images. Each candidate is tested against its fully resolved reference — an absolute URL for web content, or the resolved local path for a local resource.

Chilkat Android™ Downloads

Android™
// 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);

    CkMht mht = new CkMht();

    //  Add an exclusion pattern for embeddable resources.  Each candidate resource is tested against its
    //  fully resolved reference (an absolute URL for web content), so resources whose reference matches
    //  the pattern are omitted from the archive.  Here, resources ending in ".gif" are excluded.
    mht.ExcludeImagesMatching("*.gif");

    //  Create the MHT web archive without the excluded resources.
    String mhtText = mht.getMHT("https://example-code.com/crumb/index.html");
    if (mht.get_LastMethodSuccess() == false) {
        Log.i(TAG, mht.lastErrorText());
        return;
        }

    Log.i(TAG, mhtText);

  }

  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."
  }
}