Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
Kotlin android fundamentals intents 400x277
  • Overview
  • Transcript

2.5 Accepting Incoming Intents From Other Apps

In this lesson, you’ll learn how to make your app ready to accept requests coming from other apps. I’ll show you how to handle incoming send requests for images and messages. This means that your app will be listed as an option when a user chooses to share content.

Related Links

2.5 Accepting Incoming Intents From Other Apps

In this lesson we will learn accepting incoming intents from other apps. That is, we want to list our application to be able to handle certain requests coming from other applications. To do that we need to define three things for our activities. The first is action, second is category, the third is data. Now what each of it means? In the previous lesson, we had discussed that it is used by intent resolution to determine or to match the applications dynamically to handle request. Now action determines what to do. That is, what kind of action has to be performed. For example, action_view, action_send. Now category. After matching the action, the intent resolution comes to category. What category determine is which Android Component can handle? Now there are numerous categories that are supported by the system. But mostly the default, launcher and browsable is used. Default category means the activity will be able to be launched from start activity or start activity result. Launcher means your activity can be launched by the app launcher. Or let's say it will be the launcher activity of your application. Or the category can be browsable, which means that the activity can be invoked from a browser. That is what browsable category is. Then comes the data. Data means what kind of data can be handled by the activity? Now the data which you can define with your intent filter is uri, which is of the pattern scheme, host, port and path. First, the scheme will be filtered, then the host will be filtered, then the port, and then the path. And the next type of data is the mimeType. It can be text/plain, or it can be image which can be of all kind, and many others. These are a few examples which I gave. Now let us move to Android Studio and add an intent filter to our app. Actually, we have already been working with it. You can see in our main activity the intent filter is defined. This is used by the intent resolution to determine what kind of request this activity can handle. So here, the action which we talked about is defined in the action tag. And here the action is MAIN, which means that this activity is the main entry point and does not expect to receive any data. And then the category here is LAUNCHER, which means that this will be the launcher activity and can be detected by the app launcher. Now you can define as many intent filters as you want for an activity. I'll show you a sample intent filter so that we will be able to receive requests from the incoming intent in our application. Let's say I want this main activity to handle a share request. To do that, I'll define an intent filter here, for which I'll define the action as android.intent.action.SEND. I'll keep the category as default for now. And then, we need to define the data. We will go for the mimeType now. The mimeType text/plain shows that our activity can handle action send for text type data. And then let us make it capable for image type as well. So here, now our app should come up in the list when we generate a request to share a text or image. So now let us run our application so that the latest one is available in the emulator. So this is our application. And here our main activity has got another intent filter. Now let us go to the file manager. And here, on opening this image and choosing to share it, here we have our application coming up in the list. So here, we have successfully added the intent filter to use our application to accept the incoming request for sharing the files. Here the image file. Like we customized our application to accept the send option. Similarly, all these applications have implemented this intent filter for their application for particular activities. In the next lesson I'll show you how to create a custom action for intent. So, without wasting further time let's go.

Back to the top