Android 将事件插入日历时出错
我试图从片段中将事件插入Android 将事件插入日历时出错,android,android-intent,calendar,Android,Android Intent,Calendar,我试图从片段中将事件插入日历,但我不断收到一个错误,即找不到任何活动来处理意图 这里是错误- android.content.ActivityNotFoundException:找不到可处理Intent的活动{act=android.Intent.action.INSERT cat=[android.Intent.category.APP_CALENDAR]typ=vnd.android.cursor.item/event(具有附加项)} 这是我的密码: Intent intent = new
日历
,但我不断收到一个错误,即找不到任何活动来处理意图
这里是错误-
android.content.ActivityNotFoundException:找不到可处理Intent的活动{act=android.Intent.action.INSERT cat=[android.Intent.category.APP_CALENDAR]typ=vnd.android.cursor.item/event(具有附加项)}
这是我的密码:
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>
如果您已经知道了这些信息,您不需要启动日历应用程序,只需将事件插入数据库即可
同时查看文档
APP\u日历
仅与ACTION\u MAIN
一起使用,而不是ACTION\u INSERT
I used Intent Intent Intent=new Intent(Intent.ACTION\u EDIT);它似乎解决了一些设备中可能没有安装日历应用程序的问题。因此,请将其包含在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();
}
检查是否有任何活动可解决此目的
if (intent.resolveActivity(getPackageManager()) == null) {
}
HTC Sense Android 4.0也有同样的问题。这很烦人,因为官方的做法是使用ACTION_INSERT(参考:我使用的是安卓4.0.3版本的am HTC EVO,INSERT和EDIT都给了我ActivityNotFoundException。