Java tutorial
//package com.java2s; /* * Copyright 2014 Lorenzo Villani * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.content.Intent; import android.provider.CalendarContract; import java.util.Date; public class Main { /** * Builds an Intent to add a new event to the calendar. * * @param title The title of the event. * @param start The start date and time. * @param end The end date and time. */ public static Intent getAddEventIntent(final String title, final Date start, final Date end) { return getAddEventIntent(title, start, end, null); } /** * Builds an Intent to add a new event to the calendar. * * @param title The title of the event. * @param start The start date and time. * @param end The end date and time. * @param where Where the event is held (e.g.: an address). */ public static Intent getAddEventIntent(final String title, final Date start, final Date end, final String where) { Intent intent = new Intent(Intent.ACTION_INSERT); intent.setData(CalendarContract.Events.CONTENT_URI); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.getTime()); intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.getTime()); intent.putExtra(CalendarContract.Events.TITLE, title); if (where != null) { intent.putExtra(CalendarContract.Events.EVENT_LOCATION, where); } return intent; } }