2

I have a calendar app (Samsung default on Note 3 / Lollipop) which is invoked and properly inserts the contents of a downloaded .ics file when I open it. I'm trying to find the proper intent setAction and setType values to submit the file from within a custom app. An "almost there" solution seems to be ACTION_VIEW and text/calendar, respectively - the calendar app appears briefly, but no insertion is done. The code snippet is as follows:

intent.setDataAndType(Uri.fromFile(file), "text/calendar"); intent.setAction(Intent.ACTION_VIEW);

There are countless examples of using parsed data presented as extras with the type vnd.android.cursor.item/event, but I have yet to find an answer for this method. Does anyone know the intent make-up of the Samsung (or for that matter, Gmail) calendar?

1 Answers1

0

i've just tried this and it worked: Remember to add things in manifet and create FileProvider (android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData())

    try {
                var i = Intent(Intent.ACTION_VIEW);
                val fileUri = FileProvider.getUriForFile(
                    this,
                    BuildConfig.APPLICATION_ID + ".provider",
                    file
                )
                Log.d("Uri: {}", fileUri.toString())
                i.setDataAndType(fileUri, "text/calendar")
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                i.addFlags(FLAG_GRANT_READ_URI_PERMISSION)
                startActivity(i)
                Log.d("Open App:", "File opened successfully")
            } catch (e: Exception) {
                Log.d("Open App:", e.message.toString())
                Toast.makeText(this,"There was an error while opening the file",Toast.LENGTH_SHORT).show();
            }