Sample code for 30+ languages & platforms
Android™

Add an iCalendar Meeting Invitation to an Email

See more Email Object Examples

Demonstrates the Chilkat Email.AddiCalendarAlternativeBody method, which adds or replaces an iCalendar body as a text/calendar alternative. The first argument is the iCalendar content and the second is the iCalendar method (such as REQUEST, REPLY, or CANCEL). If an iCalendar alternative already exists it is replaced, so repeated calls leave at most one. This example attaches a simple meeting request.

Background: When you receive a calendar invite that your mail client shows with Accept/Decline buttons, it arrives as an iCalendar (.ics) body carried in the message as a text/calendar alternative. The METHODREQUEST to invite, CANCEL to withdraw, REPLY to respond — tells the recipient's client how to treat it. Delivering it as an alternative means clients that understand calendars show the invite UI, while others fall back to the plain-text or HTML body.

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 AddiCalendarAlternativeBody method, which adds (or replaces) an
    //  iCalendar body as a text/calendar alternative.  The first argument is the iCalendar content and the second
    //  is the iCalendar method (such as REQUEST, REPLY, or CANCEL).

    CkEmail email = new CkEmail();
    email.put_Subject("Meeting invitation");
    email.SetTextBody("You are invited to the Project Sync meeting.","text/plain");

    //  The iCalendar (VCALENDAR) content.  In practice this is generated iCalendar text.
    String ical = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:REQUEST\r\nBEGIN:VEVENT\r\nSUMMARY:Project Sync\r\nDTSTART:20260720T160000Z\r\nDTEND:20260720T163000Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";

    //  Add the iCalendar as a text/calendar alternative using the REQUEST method.
    email.AddiCalendarAlternativeBody(ical,"REQUEST");

    Log.i(TAG, "NumAlternatives = " + String.valueOf(email.get_NumAlternatives()));

  }

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