In Android, an Intent is a message which allows you to request functionality from other Android components, whether those components are from the same application or from a different one. An intent can be used for instance to open an activity from the same app or to open an activity from another app.
In SongExplorerForAll v6, we created an about menu in the action bar. Here, clicking on the about menu displays a dialog which gives information about the app.
When creating an intent, we have to specify the type of action to perform. Here, we use ACTION_VIEW which is basically used when we need to display data to the user.
Another type of action is ACTION_SEND. This is used when we want the user to be able to share some data through another app. In SongExplorerForAll v8, when the user clicks on the share icon in the action bar, the latter will be able to share information about the Song Explorer For All app. The user is presented with a list of apps which can perform the sharing action (e.g. Gmail), from which he/she can choose.
There are two types of intents namely explicit intents and implicit intents. When using explicit intents, we have to explicitly specify the component to start by name. On the other side, when using implicit intents, we simply declare the action to perform. The Android system then finds appropriate component(s) to handle the intent. If there are several apps which can handle the intent, we can show a chooser dialog.
In Android, Content Providers allows applications to share and use data across the platform. Android has a number of built-in providers for the data stored on the phone: e.g. contacts, call logs, media files and settings. In SongExplorerForAll v9, when the user clicks on the share icon, the latter can select a picture on his/her phone which will be sent as part of the data being share. This is done by:
- Using an intent of action type ACTION_PICK to access the MediaStore
- Handling the data returned, which is basically the URI of the image selected by the user, in the onActivityResult() method
- Adding the image URI (Intent.EXTRA_STREAM) to the ACTION_SEND intent