android - 使用 Intent 将事件插入日历时出错

标签 android android-intent calendar

我正在尝试从一个 fragment 中将事件插入到 calendar 中,但我不断收到一个错误,指出没有找到处理 Intent 的 Activity 。

这是错误 -

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT cat=[android.intent.category.APP_CALENDAR] typ=vnd.android.cursor.item/event (has extras) }

这是我的代码:

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 过滤器

<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>

最佳答案

我使用 Intent intent = new Intent(Intent.ACTION_EDIT);它似乎解决了问题

关于android - 使用 Intent 将事件插入日历时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9926830/

相关文章:

android - java.lang.NoClassDefFoundError,在我自己的类(class)之一

java - JPA - 按周数获取实体 - Java EE

android - 如何避免每次远程运行 Android 应用程序时手动打开、滑动和解锁屏幕

java - 静态x私有(private): Cost of visibility of values

java - BitmapFactory类型中的方法decodeResource(Resources, int)不适用于Android中的参数(Resources, String)

java - 在 fragment 中显示默认计算器

android - 跟踪 Android 应用程序的卸载

date - 日历系统名称的国际标准

ios - 获取不超过两个字母的日历工作日符号

android - 如何从 TabHost Activity 返回结果(startActivityForResult)?