2012-08-28 50 views
0

加3級的事件我有了這個代碼安卓:一次

   Calendar cal = Calendar.getInstance(); 
       cal.set(Integer.parseInt(data_scelta_splittata[2]),Integer.parseInt(data_scelta_splittata[1]),Integer.parseInt(data_scelta_splittata[0]),Integer.parseInt(ora_scelta_splittata[0]),Integer.parseInt(ora_scelta_splittata[1])); 
       Intent intent = new Intent(Intent.ACTION_EDIT); 
       intent.setType("vnd.android.cursor.item/event"); 
       intent.putExtra("beginTime", cal.getTimeInMillis()); 
       intent.putExtra("allDay", "allDayFlag"); 
       intent.putExtra("rrule", "FREQ=DAILY"); 
       intent.putExtra("endTime", cal.getTimeInMillis()); 
       intent.putExtra("title", "Avviso Bioscalin "+prodotto); 
       startActivity(intent); 

的問題是,我需要在同一時間增加3個事件,該代碼添加一個事件,並提示給用戶的日曆加入預編譯,但我不能這樣做3次,這對用戶來說很無聊。任何想法?

+0

您是否嘗試過使用循環? – MrYanDao

+0

不,因爲我不知道它是否解決了用戶的問題 – Zak

+1

不確定,但我懷疑你可以在沒有用戶交互(很容易)的情況下添加一個事件。你是否嘗試過使用日曆api來進行事件?也許這是要走的路...... – WarrenFaith

回答

0

如果你在4.0+以上工作,那麼有CalendarContract。然而,在ICS之前,您的選擇有限。即使您現在啓動的活動無法在製造商更換日曆應用的Android設備上使用。

沒有任何方法可以操縱vnd.android.cursor.item意圖保持沉默或執行多個請求。此外,儘管您可以通過各種意圖與日曆應用程序進行交互,但此交互操作未記錄,因此不推薦。

您可能會考慮改爲使用Google Calendar API通過REST與用戶的日曆進行交互。只要您想與之互動的日曆是與用戶的Google帳戶關聯的日曆,此方法就會爲您提供適用於任何Android API級別的代碼以及已替換股票日曆應用的設備。缺點是它不會讓您將事件添加到用戶的Outlook日曆中。

+0

我已經解決了使用此問題:http://www.developer.com/ws/android/programming/Working-with-the -Android個歷3850276.htm – Zak