私の Android アプリは、新しい G カレンダー イベントを作成します。
ユーザーは、すべての必須フィールドを G-calendar アクティビティに入力してから保存します。
ユーザーがイベントを保存した後、モバイル DB に詳細を保存したいと考えています。
つまり、フローは次のとおりです。
「新しいイベント」ButtonView をクリックします --> カレンダー UI が開きます --> ユーザーがフィールドに入力します --> カレンダー UI が閉じます --> クライアントはすべてのフィールド (event_id に関連するもの) をローカルの sqlite DB に保存します
私は2つのオプションを試しました。
(オプション A) ユーザーがデータを入力するために G-Calendar アクティビティを開かない
(オプション B) G-Calendar アクティビティを開きますが、ユーザーが入力したデータを取得するための event_id を取得できません。
private void exportToGCalendar() {
//option A
//Here is an example of inserting an event. This is being performed in the UI thread for simplicity. In practice, inserts and updates should be done in an asynchronous thread to move the action into a background thread. For more information, see AsyncQueryHandler.
long calID = 3;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2012, 9, 14, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2012, 9, 14, 8, 45);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Jazzercise");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
Uri uri = cr.insert(Events.CONTENT_URI, values);
// get the event ID that is the last element in the Uri
mEventId = Long.parseLong(uri.getLastPathSegment());
//
// ... do something with event ID
//
//
//=======
//option B
//addCalendarEvent_optionB();
}
private void addCalendarEvent_optionB() {
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, "Learn Android");
intent.putExtra(Events.EVENT_LOCATION, "Home suit home");
intent.putExtra(Events.DESCRIPTION, "Download Examples");
// Setting dates
GregorianCalendar calDate = new GregorianCalendar(2012, 10, 02);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
calDate.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calDate.getTimeInMillis());
// Make it a full day event
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
// Make it a recurring Event
intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");
// Making it private and shown as busy
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
intent.putExtra(Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
// intent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(intent);
}
どうすれば目標を達成できますか?