我已成功將事件添加到本機日曆中,並且對於Android API級別14或更高版本可以正常工作。ActivityNotFoundException在運行2.3的設備上進行測試時
我試了@ VishalKhakhkhar的代碼,但我仍然無法解決這個問題?我收到提示:未找到可處理意向{行動= android.intent.action.EDIT典型值= vnd.android.cursor.item活動/事件運行2.3.6
看到設備上測試時我下面更新的代碼,嘗試解決此問題: -
Button btnEvents = (Button) findViewById(R.id.button1);
btnEvents.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2014, 1, 16, 16, 0);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2014, 1, 16, 22, 30);
endMillis= endTime.getTimeInMillis();
if (Build.VERSION.SDK_INT >= 14) {
Intent intent = new Intent(Intent.ACTION_EDIT).setData(Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startMillis)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endMillis)
.putExtra(Events.TITLE, "Title")
.putExtra(Events.DESCRIPTION, "Description")
.putExtra(Events.EVENT_LOCATION, "Location")
.putExtra(Reminders.HAS_ALARM, true)
.putExtra(Reminders.METHOD, Reminders.METHOD_DEFAULT);
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "Title");
intent.putExtra("description", "Description");
intent.putExtra("beginTime", startMillis);
intent.putExtra("allDay", false);
intent.putExtra("endTime", endTime.endMillis);
intent.putExtra("eventLocation", "Location");
intent.putExtra("hasAlarm", 1);
startActivity(intent);
}
}
});
}
您是否檢查過[此示例?](http://www.androiddevelopersolution.com/2013/05/android-calendar-sync.html) –
這不是一個自定義日曆,只需添加一些預定義的事件,它不會爲我工作 – Sun
你有相同的任何解決方案.. ??我也必須在我的項目中實施它... – Bhavna