Skip to content

Intent Filters in Android | Example code

  • by

Intent Filters definition in easy words is Filtering the operation and perform an Action to deliver the target component.

The intent is “Explicit Intent” with the component name field set, then it’s delivered to the target component. But in “Implicit Intent” which is typical for communication between applications, android must determine the matched activity or service (or set of receivers) on its own. How does Android do that? That’s where intent filters come in.

Let see the example you build apps for play videos and published store. Users installed and using it’s. But if someone has a video and clicked it, so does your application will launch and play this video? No, if you’d didn’t specify about the app component in intent filters.

what is android Intent Filters examples

The upper diagram shows layout presentations, how the Intent and Intent filter works. Let understand Application 2 and Application 4 has defined some step of the rule in Intent filters (In manifest). Now another Application 1 has some data like a PDF file and wants to open it. So it can just pass data in intent with set of <action> <category> <data>. Now Android system will search for the same in the system to which the application has configured to take the input of that type <action><category> <data>. After found matching, it will give you the option to choose any one apps.

An intent filter declares (define some rule or attributes) the capabilities of its parent component (Activity, Service, Broadcast receiver etc), what activity or service or broadcast receiver can do and what types can handle.

Before going in deep must read about What is an Intent and its example.

Syntax :  <intent-filter>

<intent-filter android:icon="drawable resource"
               android:label="string resource"
               android:priority="integer" >
    <action> .... </>
    <category> ... </>
    <data> ... </>
what is Intent Filters and example demonstration

Contained in :

<activity> ,<activity-alias> , <service>  ,<receiver>

Must contain:


Declares the intent action accepted, in the name attribute. The value must be the literal string value of an action, not the class constant.


<action android:name="android.intent.action.MAIN" />

Optional contain:


Declares the intent category accepted, in the name attribute. The value must be the literal string value of an action, not the class constant.


<category android:name="android.intent.category.LAUNCHER" />

Note: To receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methodsstartActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULTcategory. If you do not declare this category in your intent filter, no implicit intents will resolve to your activity.

“Official Google”


Declares the type of data accepted, using one or more attributes that specify various aspects of the data URI (schemehostportpath) and MIME type.

<data android:mimeType="text/plain"/>

Let’s build one simple Intent filters example

Step 1. Create a new project “Build Your First Android App in Kotlin
Step 2. Add Button widget in the main_activity.xml resource layout file

The button is for performing an operation.

<?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""

        android:text="Hello World!"
        app:layout_constraintTop_toTopOf="parent" />

        android:text="Go To Tutorial"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

Step 3. Add the following code in MainActivity.class

Set on Click listener in button and Create Intent instance Pass the Action Intent.ACTION_VIEW and set Data Uri.parse(url).

Now when you click the button its send intent in an Android system where it will search matching component define Intent filters. If there is more then one result then it will show multiple option otherwise open on only one.

package in.eyehunt.intentfilters;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        Button button = (Button)findViewById(;
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String url = "";
                Intent i = new Intent(Intent.ACTION_VIEW);
Step 6. Run the application, in an emulator or On you android device
Output screenshot Android Intent Filters example :
Output screenshot Android Intent Filters example

Video Output

Download source code Intent-filters example :

Note : This example (Project) is developed in Android Studio 3.1.3 . Tested on Android 9 ( Android-P), compile SDK version API 26: Android 8.0 (Oreo)



Coding in Java

Same as this example you can build your own app for browsing and define components (activity) as a target.

Bouns : 

Even you are not aware you can check your AndroidManifest.xml file, where your main activity also using an Intent filter. Without Define <action> and <category> your app will not launch because the Android system doesn’t know about which activity is the entry point of your app.

<manifest ...>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER"/>

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading