I am creating an .ics File in my Activity. I want to send the created .ics File to a calendar app on the phone, so the app can import the events.
Here is my code for the Intent:
`Intent intent = new Intent(Intent.ACTION_SEND);
intent.addCategory(Intent.CATEGORY_APP_CALENDAR);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(icsfile));
startActivity(Intent.createChooser(intent, "How do you want to share?"));`
Unfortunately no calender apps are shown in the chooser.
Google Calendar, at least, does not support responding to ACTION_SEND
.
So, try:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(icsfile), "application/ics");
startActivity(intent);
(and, eventually, switch to using FileProvider
as opposed to Uri.fromFile()
, as that does not work on Android 7.0+ for apps with a targetSdkVersion
of 23 or higher)