Open In App
Related Articles

Intent Filter in Android with Demo App

Improve Article
Save Article
Like Article

The intent is a messaging object which tells what kind of action to be performed. The intent’s most significant use is the launching of the activity. Intent facilitates the communication between the components.

Note: App components are the basic building blocks of App.

Fundamental use case of Intents

Starting Activity

An activity represents the single screen in an app, Bypassing intent instance we can start an activity.



var intent = Intent(this, SecondActivity::

You can add extra information by using putExtra().

Starting a Service

A Service is a component that performs operations in the background without a user interface, which is also called a background process.

Delivering a Broadcast

A broadcast is a message that any app can receive. In android, the system delivers various broadcast system events like device starts charging, disable or enable airplane mode, etc.

Intent Type

There are two types of intent

  1. Explicit intent: Explicit intent can do the specific application action which is set by the code like changing activity, In explicit intent user knows about all the things like after clicking a button which activity will start and Explicit intents are used for communication inside the application
  2. Implicit Intent: Implicit intents do not name a specific component like explicit intent, instead declare general action to perform, which allows a component from another app to handle.

For example: when you tap the share button in any app you can see the Gmail, Bluetooth, and other sharing app options. 

Intent Filter

  • Implicit intent uses the intent filter to serve the user request.
  • The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond.
  • Intent filters are declared in the Android manifest file.
  • Intent filter must contain <action>



  android:icon="drawable resource"
  android:label="string resource"
  android:priority="integer" >
   . . .

Most of the intent filter are describe by its 

  1. <action>, 
  2. <category> and
  3. <data>.

1. <action>



<action android:name="string" />

Adds an action to an intent filter. An <intent-filter> element must contain one or more <action> elements. If there are no <action> elements in an intent filter, the filter doesn’t accept any Intent objects.

Examples of common action:

  • ACTION_VIEW: Use this action in intent with startActivity() when you have some information that activity can show to the user like showing an image in a gallery app or  an address to view in a map app
  • ACTION_SEND: You should use this in intent with startActivity() when you have some data that the user can share through another app, such as an email app or social sharing app.

2. <category>



<category android:name="string" />

Adds a category name to an intent filter. A string containing additional information about the kind of component that should handle the intent.

Example of common categories:

  • CATEGORY_BROWSABLE: The target activity allows itself to be started by a web browser to display data referenced by a link.

3. <data>



<data android:scheme="string"
      android:mimeType="string" />

Adds a data specification to an intent filter. The specification can be just a data type, just a URI, or both a data type and a URI.

Note: Uniform Resource Identifier (URI) is a string of characters used to identify a resource. A URI identifies a resource either by location, or a name, or both.

Implementation of Intent Filter with a Demo App

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.

Step 2: Add dependencies to the build.gradle(Module:app) file

Add the following dependency to the build.gradle(Module:app) file. We are adding these two dependencies because to avoid using findViewById() in our MainActivity.kt file. Try this out otherwise use the normal way like findViewById().

apply plugin: ‘kotlin-android’

apply plugin: ‘kotlin-android-extensions’

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
        app:layout_constraintVertical_bias="0.153" />
        app:layout_constraintVertical_bias="0.826" />

Step 4: Working with the AndroidManifest.xml File

Following is the code for the AndroidManifest.xml File.


<?xml version="1.0" encoding="utf-8"?>
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            <!--SEND INTENT FILTER-->
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain"/>
            <!--VIEW INTENT FILTER-->
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="http"/>

Step 5: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.


package com.example.intentfilter
import android.content.Intent
import android.os.Bundle
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // send button on click listener
        sendButton.setOnClickListener {
            var intent = Intent(Intent.ACTION_SEND) // intent
            intent.type = "text/plain"
            intent.putExtra(Intent.EXTRA_EMAIL, "")
            intent.putExtra(Intent.EXTRA_SUBJECT, "This is a dummy message")
            intent.putExtra(Intent.EXTRA_TEXT, "Dummy test message")
        // View on click listener
        buttonView.setOnClickListener {
            var intent = Intent(Intent.ACTION_VIEW)

Output with Explanation:

Click on Send Button, you will see a screen like this,

Now choose Gmail app,

Now go to our app and click the view button,

our app dummy app. You can any app from these options because we are using a view intent filter.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 07 Mar, 2021
Like Article
Save Article
Similar Reads