在我的应用程序中我有一个日历功能,其中我在布局文件中有一个按钮,点击我希望它直接在默认日历中添加预定义的3天全天约会事件。我跟随java代码可以任何人指导我需要添加其他什么来让它工作...
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar cal = Calendar.getInstance();
cal.set(year, mnth, day, hrs, min);
long beginTime = cal.getTimeInMillis();
cal.set(year, mnth, day, hrs, min);
long endTime = cal.getTimeInMillis();
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("endTime",
cal.getTimeInMillis() + 60 * 60 * 1000);
intent.putExtra("title", "A Test Event from android app");
startActivity(intent);
}
});
感谢和问候
答案 0 :(得分:0)
这应该有效:
...
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTimeInMillis());
cal.add(Calendar.DATE, 3);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, cal.getTimeInMillis());
...