2

我的 android 应用程序创建了一个新的 G 日历事件。

用户将所有必填字段放入 G 日历活动中,然后保存。

在用户保存事件后,我想将详细信息保存在我的移动数据库中。

即流程是:

单击“新事件” ButtonView --> 日历 UI 打开 --> 用户填写字段 --> 日历 UI 关闭 --> 客户端将所有文件(与 event_id 相关)保存在本地 sqlite 数据库中

我已经尝试了 2 个选项。

(选项 A)不打开 G-Calendar Activity 供用户填写数据

(选项 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);
}

我怎样才能实现我的目标?

4

0 回答 0