1

How would I have a user pick an event from their device calendar?

Android Calendar Provider Documentation and this question state that you can view the calendar using an Intent like so:

long startMillis = System.currentTimeMillis();

// using content://com.android.calendar/time/<ms_since_epoch>

Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, startMillis);
Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
startActivity(intent);

However, this only allows us to open the calendar for viewing, using intents.

How would I have the intent return the event ID upon selection?


UPDATE 1: For grins, looking in the Developers Guide, I'm going to try to do a Intent.ACTION_PICK instead of Intent.ACTION_VIEW. ACTION_PICK isn't defined in the Calendar Provider but its worth a shot. Note that Intent.ACTION_VIEW did work previously.

UPDATE 2: As probably expected, the runtime threw this when using ACTION_PICK:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://com.android.calendar/time/1475990157934 }

It seems using intents are out of the question?

Community
  • 1
  • 1
Kevin Thorne
  • 435
  • 5
  • 19

1 Answers1

0

Seems like your device have no Calendar application. I would advice you to use intent.resolveActivity(getContext().getPackageManager() != null check every time you are trying to send an implicit intent. The only way to get calendar information without Calendar app is to use a calendar content provider like it's described here

IlyaGulya
  • 957
  • 6
  • 18