Search code examples
androiddelphidelphi-xe5

Firemonkey Android Access Calendar and Events


How do I access the Calendar and Events on Android using Delphi XE5.


Solution

  • To access the calendar you can use the Calendar class which is represented by the JCalendar class in Delphi.

    You can find a set of samples here

    And this is a Delphi sample

    uses
      Androidapi.JNI.GraphicsContentViewText,
      FMX.Helpers.Android,
      Androidapi.JNI.JavaTypes;
    
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Intent: JIntent;
      Calendar: JCalendar;
    begin
      Calendar := TJCalendar.JavaClass.getInstance;
      Intent := TJIntent.Create;
      Intent.setType(StringToJString('vnd.android.cursor.item/event'));
      intent.putExtra(StringToJString('beginTime'), Calendar.getTimeInMillis());
      intent.putExtra(StringToJString('allDay'), true);
      intent.putExtra(StringToJString('rrule'), StringToJString('FREQ=YEARLY'));
      intent.putExtra(StringToJString('endTime'), Calendar.getTimeInMillis()+3600*1000);
      intent.putExtra(StringToJString('title'), StringToJString('Hello from Delphi'));
      SharedActivity.startActivity(Intent);
    end;