Android Calendar Intent Event End Always One Hour After Start
I've looked into this problem a lot and I can't seem to find anyone having the same difficulties. The start time is working fine but the end time is always set to being exactly one
Solution 1:
I fixed it my using a different implementation.
public void setAlarm(Date examMonth, int day, int hourOfDay, int minute,
double length, String examName, String venue) {
Calendar calSet = Calendar.getInstance();
calSet.setTime(examMonth);
int month = calSet.get(Calendar.MONTH);
int year = Calendar.getInstance().get(Calendar.YEAR);
calSet.set(year, month, day, hourOfDay, minute, 0);
// look for calendar
Cursor cursor = getContentResolver()
.query(Uri.parse("content://com.android.calendar/calendars"),
new String[] { "_id", "calendar_displayName" },"visible='1'"
, null, null);
cursor.moveToFirst();
String[] CalNames = new String[cursor.getCount()];
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CalNames.length; i++) {
CalIds[i] = cursor.getInt(0);
CalNames[i] = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
// put calendar event
ContentValues event = new ContentValues();
event.put("calendar_id", CalIds[0]);
event.put("title", examName);
//event.put("description", description);
event.put("eventLocation", venue);
event.put(Events.ALL_DAY, 0);
event.put("dtstart", calSet.getTimeInMillis());
event.put("dtend", (float)(length*3600000)+calSet.getTimeInMillis());
event.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
event.put(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
event.put("hasAlarm", 1);
Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Uri newEvent = getContentResolver().insert(eventsUri, event);
// put alarm reminder for an event, 2 hours prior
long eventID = Long.parseLong(newEvent.getLastPathSegment());
ContentValues cv_alarm = new ContentValues();
cv_alarm.put("event_id", eventID);
cv_alarm.put("method", 1);
cv_alarm.put("minutes", 120);
this.getContentResolver()
.insert(Uri.parse("content://com.android.calendar/reminders"),
cv_alarm);
}
Post a Comment for "Android Calendar Intent Event End Always One Hour After Start"