以下设置的提醒代码在特定设备上崩溃。我认为是因为它没有安装日历应用程序。
如何检查设备中是否安装了日历应用程序?日历应用程序可以是任何,三星,谷歌或任何其他。
我需要检查是否有应用程序来处理日历意图。日历使用的目标过滤器是什么,以及如何检查设备中是否有应用程序来处理该意图。
public void setReminder(View v)
{
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
switch (v.getId())
{
case R.id.saganReminder:
GregorianCalendar beginCalDate = new GregorianCalendar(2016, 8,9,19,00);
// GregorianCalendar endCalDate = new GregorianCalendar(2016, 8,9,10,00);
intent.putExtra("title", getResources().getString(R.string.saganReminderName));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
intent.putExtra(CalendarContract.Events._ID,1);
intent.putExtra(CalendarContract.Events.CALENDAR_ID,1);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, getResources().getString(R.string.sagan_venue_calender));
intent.putExtra(CalendarContract.Events.DESCRIPTION, getResources().getString(R.string.CalenderDescriptionSagan));
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
beginCalDate.getTimeInMillis());
// intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
// endCalDate.getTimeInMillis());
intent.putExtra(CalendarContract.Events.ACCESS_LEVEL, CalendarContract.Events.ACCESS_PRIVATE);
intent.putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
intent.putExtra(CalendarContract.Events.CALENDAR_COLOR, CalendarContract.Colors.COLOR_KEY);
intent.setData(CalendarContract.Events.CONTENT_URI);
}
else
{
intent.putExtra("beginTime", beginCalDate.getTimeInMillis());
//intent.putExtra("endTime", endCalDate.getTimeInMillis());
intent.putExtra("description", getResources().getString(R.string.CalenderDescriptionSagan));
intent.putExtra("eventLocation", getResources().getString(R.string.sagan_venue_calender));
intent.putExtra("allDay", true);
}
break;
}
崩溃的堆栈跟踪:
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.a.bk.onClick(Unknown Source)
at android.view.View.performClick(View.java:4470)
at android.view.View$PerformClick.run(View.java:18599)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
... 12 more
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=content: (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1771)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1563)
at android.app.Activity.startActivityForResult(Activity.java:3505)
at android.support.v4.b.t.startActivityForResult(Unknown Source)
at android.support.v4.b.z.startActivityForResult(Unknown Source)
at android.app.Activity.startActivityForResult(Activity.java:3466)
at android.support.v4.b.z.startActivityForResult(Unknown Source)
at android.app.Activity.startActivity(Activity.java:3708)
at android.app.Activity.startActivity(Activity.java:3676)