LoginSignup
1
0

More than 5 years have passed since last update.

[Delphi] インテントを使用してカレンダーを参照する

Last updated at Posted at 2018-03-20

インテントを使用したカレンダー データの参照
https://developer.android.com/guide/topics/providers/calendar-provider.html#intent-view
の手法を使って、Android で Google カレンダーを参照してみた

カレンダーのインテントを利用すると、パーミッションの要求を行なう事なく、カレンダーアプリケーション側にユーザーを誘導して、参照や、イベントの挿入などを行なうことができます

サンプルコード

フォーム上にボタンを置き、ボタンのクリックイベントで以下を記述


// uses に Androidapi.Helpers, Androidapi.JNI.APP, Androidapi.JNI.Provider,
//         Androidapi.JNI.JavaTypes, Androidapi.JNI.Net,
//         Androidapi.JNI.GrapicsContentViewText を追加します

// インテントは Intent: JIntent; で定義しています
// uri は uri: JUri_Builder; で定義しています
// カレンダーは mCalendar: JCalendar; で定義しています

// 今日の日付を取得します
mCalendar := TJCalendar.JavaClass.getInstance;

// uri buildUpon を使用して必要なパラメータを設定
uri := TJCalendarContract.JavaClass.CONTENT_URI.buildUpon;
uri.appendPath(stringToJString('time'));
TJContentUris.JavaClass.appendId(uri, mCalendar.getTimeInMillis);

// インテントを作成します
Intent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_VIEW);

// 参照する日付をセットします
Intent.setData(uri.build);

// startActivity を使ってインテントを飛ばします。
TAndroidHelper.Activity.startActivity(Intent);

今日から 10 日後という場合は


// 今日の日付を取得して +10日します
mCalendar := TJCalendar.JavaClass.getInstance;
mCalendar.add(TJCalendar.JavaClass.DATE, 10);

のように記述します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0