是否可以知道用户是否选择取消 Android 上的日历事件插入?

Is it possible to know if user opted to cancel calendar event insertion on Android?

我正在使用以下方法启动日历插入 activity:

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");

Calendar cal = Calendar.getInstance();
long startTime = cal.getTimeInMillis();
long endTime = startTime + 60 * 60 * 1000;

intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime);
intent.putExtra(Events.TITLE, "Frank Zappa Live");
intent.putExtra(Events.EVENT_LOCATION, "Madison Square Garden");

startActivity(intent);

到目前为止一切顺利。但是我怎么知道用户是否选择取消?

你应该使用 startActivityForResult 你会得到 Activity#RESULT_OKActivity#RESULT_CANCEL 结果。

发件人:https://developer.android.com/reference/android/provider/CalendarContract#ACTION_HANDLE_CUSTOM_EVENT