如何自动将事件添加到日历?如果我使用这个源代码,它会打开带有填充条目的日历,但我必须单击保存按钮来保存它。
public class CalendarApplicationActivity extends Activity
{
public static final String[] EVENT_PROJECTION = new String[]
{
Calendars._ID, // 0
Calendars.ACCOUNT_NAME, // 1
Calendars.CALENDAR_DISPLAY_NAME // 2
};
private static final int PROJECTION_DISPLAY_NAME_INDEX = 2;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar_application);
}
public void onClick(View view)
{
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");
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());
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
startActivity(intent);
}
}