我的Android应用程序会创建一个新的G日历事件。
用户将所有必填字段放入G日历活动中,然后保存。
我希望在用户保存活动后,在我的移动数据库中保存详细信息。
即。流程是:
点击“新活动”ButtonView - >日历用户界面打开 - >用户填写字段 - >日历用户界面关闭 - >客户端将所有文件(与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);
}
我如何实现目标?