0% found this document useful (0 votes)
31 views2 pages

Intent Filter

The document explains the concept of intent filters in Android, which connect different applications to enhance user experience by resolving intents for activities, services, and broadcast receivers. It provides syntax and attributes for defining intent filters in the AndroidManifest.xml, including examples of XML layout and Java code for sending an email through an intent. The document also illustrates how to declare an intent filter for the main activity and the send action with specific MIME type.

Uploaded by

sonetshaji2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Intent Filter

The document explains the concept of intent filters in Android, which connect different applications to enhance user experience by resolving intents for activities, services, and broadcast receivers. It provides syntax and attributes for defining intent filters in the AndroidManifest.xml, including examples of XML layout and Java code for sending an email through an intent. The document also illustrates how to declare an intent filter for the main activity and the send action with specific MIME type.

Uploaded by

sonetshaji2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Intent_filer

It is a powerful way to connect different applications together hence allowing better user
experience. They take care of intent resolution to match activities, services and broadcast receiver.
They are declared in AndroidManifest.xml. An intent filter is an instant of the intent filter class. It
declares the capability of its parent component.

Syntax

<intent_filter android:icon=”drawable resource” android:label=”string resource”


android:priority=”integer”>

</intent_filter>

Attributes

android:icon: It represent the parent activity, service or broadcast receiver when that component is
existing to the user as having the potential described by the filter. This attribute must be set as a
reference to a drawable resource containing the image definition. The defaulting value is the icon set
by the parent component’s icon attribute. If the aren’t do not specify an icon, the default is the icon
set by the <application> element.

android:label: A user-readable label for the parent component. This label is used, when the
component is offered to the user as having the capability described by the filter. The label should be
set as a reference to the string resource so that it could be localized by other strings in the user
interface. The default value is the label set by the parent component. If the parent dose not specify a
label, the default is the label set by the <application> element’s label attribute.

Program
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/sendMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="230dp"
android:text="Send Mail" />
</LinearLayout>

package com.example.intentfilter;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.content.Intent;

import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnSend = (Button)findViewById(R.id.sendMail);
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent si = new Intent(Intent.ACTION_SEND);
si.setType("message/rfc822");
si.putExtra(Intent.EXTRA_EMAIL, new String[]
{"[email protected]"});
si.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Intent
Filters");
si.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Intent
Filters...!!!");
startActivity(Intent.createChooser(si,"Choose Mail App"));
}
});
}
}

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intentfilter">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Intentfilter">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="message/rfc822"/>
</intent-filter>
</activity>
</application>

</manifest>

You might also like