编辑模式下的Google日历活动计时会自动添加或减少小时数

时间:2016-09-16 16:17:20

标签: android events google-calendar-api

我做了以下代码,以编程方式在Google日历中创建活动:

Uri eventsUri = Uri.parse("content://com.android.calendar/events");
            ContentValues event = new ContentValues();
            event.put("calendar_id", 1);
            event.put("title", generate_title);
            event.put("description", "Swim Lesson in " + ScheduleLessonFragement5.Calendar_Event.get(i).get("sitename"));
            event.put("eventLocation", ScheduleLessonFragement5.Calendar_Event.get(i).get("sitename"));
            event.put("dtstart", startMillis);
            event.put("dtend", endMillis);
            event.put("allDay", 0);   // 0 for false, 1 for true
            event.put("eventStatus", 1);
            event.put("hasAlarm", 1); // 0 for false, 1 for true
            event.put("eventTimezone", TimeZone.getDefault().toString());


            try {
                Uri eventUri = getApplicationContext().getContentResolver().insert(eventsUri, event);
                eventids.add (eventUri.getLastPathSegment());
                ContentValues reminders = new ContentValues();
                reminders.put(CalendarContract.Reminders.EVENT_ID, eventUri.getLastPathSegment());
                reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
                reminders.put(CalendarContract.Reminders.MINUTES, 30);

                Uri uri2 = getApplicationContext().getContentResolver().insert(CalendarContract.Reminders.CONTENT_URI, reminders);
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
        System.out.println(""+eventids);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("content://com.android.calendar/events/" + String.valueOf(eventids.get(0))));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        Utility.ping(this, "Events added successfully in Calendar.");`

上面的代码确实创建了事件,并且还打开了第一个事件,其中插入的时序在视图模式下显示,但是当我按下编辑模式时,它会从给定的时间中减去5:30小时。 而对于我的客户来说,它可以在应用程序中为他提供的时间增加7小时。示例图像已在下面给出....我搜索了很多,它说问题是关于时区...我没有得到它.. When open calendar event in view mode When open calendar event in edit mode

此外,我通过以下链接但没有成功:

enter link description here

0 个答案:

没有答案