How to implement implicit and explicit Android Intents in Kotlin
A guide on what implicit and explicit intents are and how to implement them in Android apps using Kotlin.
Approximately 17.53 minutes into What's new in Android privacy and security
Implicit and explicit intents were discussed during Google I/O 2023's What's new in Android privacy and security session, and have been updated such that implicit intents only available to exported components.
What are implicit intents and how do I use them ?
An implicit intent specifies an action that can invoke any app on the device able to perform the action. Using an implicit intent is useful when your app cannot perform the action, but other apps probably can and you'd like the user to pick which app to use.
Sample code on how to use implicit intents can be found below.
What are explicit intents and how do I use them ?
An explicit intent is one that you use to launch a specific app component, such as a particular activity or service in your app. To create an explicit intent, define the component name for the Intent object—all other intent properties are optional.
Specific new additions that should be considered for explicit intents are:
- setPackage - targets an exact application and offers you all components that can handle your intent.
- setClassName - Targets an exact package name and exact component you want to run. e.g. if you want to use the Gmail app to send an email using this to run the exact Activity(Component) you want to run.
Sample code on how to use explicit intents can be found below.