简体   繁体   中英

How to set the event to the device calendar through user app and get the reminder in android google calendar?

I want to set the event to the device calendar through my application. I need to fetch date and time from the edittext (which is user input) and on clicking a button (say set date and time) it should be saved to the device calendar as a event. And the provided date and time it should be remind the app user about the event.

I want the native calendar to take user input & sets the event. So for this purpose I have implemented the following code:

public void addCalendarEvent()
{
    Calendar cal = Calendar.getInstance();     
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime", cal.getTimeInMillis());
    intent.putExtra("allDay", true);
    intent.putExtra("rrule", "FREQ=YEARLY");
    intent.putExtra("UNTIL=20140404T080000Z",true);
    intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
    intent.putExtra("title", "A Test Event from android app");
    intent.putExtra("description", "A Test Description from android app");
    intent.putExtra("eventLocation", "Geolocation");
    startActivity(intent);
}

I invoked this method within the button onClick() method. I hard coded the date as:

 intent.putExtra("UNTIL=20140404T080000Z",true); 

But this will not work. However, I don't want to hard code it, it should accept user input (dynamically it should work, say fetching the edittext data and passed through intent).

Please can anybody help me in this regard?

Please anybody help me in this regard?

Yes i got it...Try this code Instead

put this code in AddEvent()

    Calendar beginTime = Calendar.getInstance();

    beginTime.set(eventBeginDate[0], eventBeginDate[1],    
    eventBeginDate[2],eventBeginTime[0], eventBeginTime[1]); // ?1

     startMillis = beginTime.getTimeInMillis();
    Calendar endTime = Calendar.getInstance();

    endTime.set(eventEndDate[0], eventEndDate[1], eventEndDate[2],
    eventEndTime[0], eventEndTime[1]);

    endMillis = endTime.getTimeInMillis();

    ContentResolver cr = getContentResolver(); // event?
    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, startMillis);
    values.put(Events.DTEND, endMillis);
    values.put(Events.TITLE, eventName);
    values.put(Events.DESCRIPTION, eventDescription);
    values.put(Events.CALENDAR_ID, calId);
    values.put(Events.EVENT_TIMEZONE, "GMT+8");
    Uri uri = cr.insert(Events.CONTENT_URI, values);
    Long myEventsId = Long.parseLong(uri.getLastPathSegment()); // eventId

    ContentResolver cr1 = getContentResolver(); // eventreminder
    ContentValues values1 = new ContentValues();
    values1.put(Reminders.MINUTES, reminderMinutus);
    values1.put(Reminders.EVENT_ID, myEventsId);
    values1.put(Reminders.METHOD, Reminders.METHOD_ALERT);
    cr1.insert(Reminders.CONTENT_URI, values1); // Uri

    setAlarmDeal(startMillis); // reminder?activity

    showMessageDialog("?" + "\n" + uri.getLastPathSegment() + "\n"
            + uri.getAuthority());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM