2011-04-06 81 views

回答

12

閱讀從日曆數據後剛剛嘗試了這一點..

添加一個帶發生事件的日曆

爲一個條目添加到特定的日曆,我們需要配置日曆項使用插入ContentValues如下:

ContentValues event = new ContentValues(); 

每個事件都需要被綁定到特定的日曆,所以你會想設置的第一件事是日曆的標識此事件插入:

event.put("calendar_id", calId); 

我們然後設置一些有關事件的基本信息,包括字符串字段,如事件標題,說明和位置。

event.put("title", "Event Title"); 
event.put("description", "Event Desc"); 
event.put("eventLocation", "Event Location"); 

配置事件的時間和日期有許多不同的選項。

我們可以設置事件的開始和結束的信息如下:

long startTime = START_TIME_MS; 
long endTime = END_TIME_MS; 
event.put("dtstart", startTime); 
event.put("dtend", endTime); 

如果我們增加一個生日或節日,我們會設置的入口是一個全天事件:

event.put("allDay", 1); // 0 for false, 1 for true 

這些信息足以滿足大多數條目。但是,還有許多其他有用的日曆條目屬性。

例如,您可以設置事件狀態暫定(0),證實了(1)或取消(2):

event.put("eventStatus", 1); 

您可以控制誰可以通過設置它的可見性默認看到此事件(0),保密(1),私人(2),或公共(3):

event.put("visibility", 0); 

您可以控制一個事件是否消耗時間通過其透明度設置爲不透明(可以有時間衝突)上的日曆(0)或透明(1)。

event.put("transparency", 0); 

您可以控制如下事件是否觸發報警提醒:

event.put("hasAlarm", 1); // 0 for false, 1 for true 

一旦日曆事件配置正確,我們已經準備好使用ContentResolver的插入新的日曆進入相應的URI的日曆事件:

Uri eventsUri = Uri.parse("content://calendar/events"); 
    Uri url = getContentResolver().insert(eventsUri, event); 

的insert()方法接觸的日曆內容提供商和嘗試調用插入進入Appro公司priate用戶日曆。如果您導航到日曆應用程序並啓動它,則應該在相應的日曆中看到您的日曆條目。由於日曆同步,因此如果您在網絡上使用Google日曆,則還會在線看到日曆條目。

添加重複發生的事件的日曆

您還可以配置定期日曆事件。爲此,您必須以重複規則的形式向事件添加更多字段。規則規範基於RFC2445

+0

'日曆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(「endTime」,cal.getTimeInMillis()+ 60 * 60 * 1000); intent.putExtra(「title」,「來自android應用程序的測試事件」); startActivity(意圖);' 否則它可能會幫助你...! – Hussain 2011-04-14 05:34:43

+0

很棒的答案..幫了我很多。謝謝。 – 2011-05-12 12:18:16

+0

@Hussain:很好的信息。乾杯 – 2012-11-21 06:20:33

1

這是該問題的確切的答案

Uri uri = Uri.parse("content://calendar/events"); 
    long eventId = calendeeventid; 
    Uri newuri = ContentUris.withAppendedId(uri, eventId); 
    Intent intent = new Intent(Intent.ACTION_VIEW,newuri); 
    Cursor cursor = getContentResolver().query(newuri, new String[]{"dtstart","dtend",},null, null, null); 
    if(cursor.getCount()>0) 
    { cursor.moveToFirst(); 
    intent.putExtra("beginTime", cursor.getLong(cursor.getColumnIndex("dtstart"))); 
    intent.putExtra("endTime", cursor.getLong(cursor.getColumnIndex("dtend"))); 
    }