2

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

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Skywalker
  • 23
  • 1
  • 7

2 Answers2

5

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;
Community
  • 1
  • 1
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • 1
    In Delphi XE6 StringToJString is declared in Androidapi.Helpers, so this unit also must be used. – dummzeuch Jun 01 '14 at 18:03
  • This code does not work anymore for new Delphi/GoogleApi version. Does anyone have updated solution? – Remi May 17 '17 at 09:44
  • 1
    You have to add the action: ACTION_INSERT in order to make this code work. Otherwise it only opens the calendar and does not insert an event. – Remi May 18 '17 at 08:25
0

in XE5 they started with PlatformServices and put Pickers Service into it: http://docwiki.embarcadero.com/Libraries/XE5/en/FMX.Pickers.IFMXPickerService

probably this piece of code will be usable for you:

  var
      PickerService: IFMXPickerService;
    begin
       if PlatformServices.Current.SupportsPlatformService(
           IFMXPickerService, Interface(PickerService))
    then
        FDateTimePicker := PickerService.CreateDateTimePicker;
        ...   // or
        FListPicker := PickerService.CreateListPicker;