2012-03-29 57 views
2

我試圖從一個片段插入事件到calendar,但我一直收到一個錯誤消息,發現沒有任何活動處理意圖。錯誤將事件插入帶有意圖的日曆

這裏的錯誤 -

android.content.ActivityNotFoundException:無活動處理意向{行動= android.intent.action.INSERT貓= [android.intent.category.APP_CALENDAR]典型值= VND .android.cursor.item /事件(有演員)}

這裏是我的代碼:

Intent intent = new Intent(Intent.ACTION_INSERT); 
intent.addCategory(Intent.CATEGORY_APP_CALENDAR); 
intent.setType("vnd.android.cursor.item/event"); 
intent.putExtra(Events.TITLE, "Phototherapy Treatment"); 
intent.putExtra(Events.EVENT_LOCATION, ""); 
intent.putExtra(Events.DESCRIPTION, "Phototherapy Treatment"); 

// Setting dates 
Calendar calDate = Calendar.getInstance(); 
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,calDate.getTimeInMillis()); 
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, 
calDate.getTimeInMillis()+60*60*1000); 

// Make it a full day event 
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false); 

// Make it a recurring Event      
intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT="+Integer.valueOf(No.getText().toString())+";" 
+"WKST=SU;BYDAY="+days); 

// Making it private and shown as busy 
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE); 
intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); 

startActivity(intent); 

意圖過濾

<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<action android:name="android.intent.action.INSERT" /> 
<category android:name="android.intent.category.APP_CALENDAR" /> 
<data android:mimeType="vnd.android.cursor.item/event" /> 
</intent-filter> 

回答

13

我使用意圖intent = new Intent(Intent.ACTION_EDIT);並且它似乎解決了問題

+1

與HTC Sense Android 4.0有同樣的問題。它令人討厭,因爲這樣做的官方方式是ACTION_INSERT(參考:http://developer.android.com/guide/topics/providers/calendar-provider.html#intents-9 – Warpzit 2012-08-10 08:16:13

+1

我使用HTC EVO與Android 4.0.3和INSERT和EDIT都給了我ActivityNotFoundException。 – 2013-08-12 08:49:09

0

如果你已經知道它看起來像你這樣做,你不需要啓動日曆應用程序,只是簡單地插入事件到數據庫see adding events

也期待在信息docs APP_CALENDAR僅與ACTION_MAIN不一致使用ACTION_INSERT

0

日曆應用程序可能未安裝在某些設備中。因此請在try catch塊內進行檢查。

Calendar startTymVar = Calendar.getInstance(); 
startTymVar.set(2015, 12, 31, 11, 30); 

Intent calendarIntentVar = new Intent(Intent.ACTION_INSERT) 
      .setData(CalendarContract.Events.CONTENT_URI) 
      .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTymVar.getTimeInMillis()) 
      .putExtra(CalendarContract.Events.TITLE, "New Year") 
      .putExtra(CalendarContract.Events.DESCRIPTION, "Hav ful fun"); 

try 
{ 
    startActivity(calendarIntentVar); 
} 
catch (ActivityNotFoundException ErrVar) 
{ 
    Toast.makeText(this, "Install Calender App", Toast.LENGTH_LONG).show(); 
} 
相關問題