Sample code for 30+ languages & platforms
Android™

Get the Value of the Nth Header Field

See more Email Object Examples

Demonstrates the Chilkat Email.GetHeaderFieldValue method, which returns the value of the Nth header field. Indexing begins at 0, and the count comes from NumHeaderFields. This example walks every header field, printing each name together with its value.

Background: GetHeaderFieldValue is the value half of index-based header enumeration — GetHeaderFieldName gives the field name at the same index. Iterating both is the reliable way to dump or inspect a full header block, including any repeated fields, which a name-based lookup would collapse to a single occurrence.

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);

    //  Demonstrates the GetHeaderFieldValue method, which returns the value of the Nth header
    //  field.  Indexing begins at 0; the number of header fields is given by NumHeaderFields.

    CkEmail email = new CkEmail();
    email.put_Subject("Enumerate header values");
    email.put_From("alice@example.com");
    email.AddTo("Bob","bob@example.com");

    int n = email.get_NumHeaderFields();
    int i;
    for (i = 0; i <= n - 1; i++) {
        Log.i(TAG, email.getHeaderFieldName(i) + " = " + email.getHeaderFieldValue(i));
        }


  }

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