androidandroid-calendar

How to create an Intent that launches Calendar app on Android?


I'm trying to add a button that launches the Calendar app on Android 13:

private fun openCalendar() {
    val intent = Intent(Intent.ACTION_VIEW).apply {
        data = CalendarContract.CONTENT_URI
        setPackage("com.android.calendar")
    }
    startActivity(intent)
}

But this throws the following Exception:

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

How can I launch the calendar in an alternative way?


Solution

  • Just use the following code:

    private fun openCalendar() {
        val intent = Intent(
            Intent.ACTION_VIEW,
            CalendarContract.CONTENT_URI.buildUpon().appendPath("time").build()
        )
        startActivity(intent)
    }
    

    This will open the calendar installed on your Android 13 device