Android: Intent and Intent filter

Intent

An Intent is a message object that delivers actions, data, and so on to a component. An intent object consists of the following:

  • Action: Action name to perform(ACTION_DIAL)
  • Data: The URI of the data to be performed(tel:)
  • Category: Additional information about the action to perform
  • Type: The explicit type(MIME type) of the intent data to be performed(video/mpeg)
  • Component name: The fully qualified class name of the target component
  • Extras: A pair of keys/values to pass in addition to the component handling the intent

An intent object is responsible for executing activities or delivering data to other applications, the most important of which is Action.

An action can be divided into an activity and a broadcast action.

Action Explanation
ACTION_MAIN Actions to specify start activities
ACTION_VIEW An action that calls the most appropriate activity with the URL of the data
content://contacts/people/1
ACTION_DEFAULT Same as ACTION_VIEW
ACTION_EDIT Action to call to modify
ACTION_DELETE Action to call to delete
ACTION_DIAL Action to call phone dial activity
content://contacts/people/1
tel:0101235678
ACTION_CALL Action that call phone activities
tel:0101235678
ACTION_WEB_SEARCH Actions that invoke web search activities
ACTION_SEARCH Action to invoke search activity
ACTION_SENDTO Action that specify message delivery, such as email
ACTION_ANSWER Action for incoming calls
Intent intent = new Intent(this, IntentCallee.class);
intent.putExtra("name", "gildong");
intent.putExtra("age", 30);
startActivity(intent);
Data transfer using intents Code implementation example 1
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 20);
Data transfer using intents Code implementation example 2

Intent Filter

The intent filter is responsible for defining whether to receive a specific intent. This determines the characteristics of the component. For example, if you declare android.intent.category.HOME in an intent filter, the component becomes a home application and becomes an application that can be started automatically when the device is started.

Intent filters are defined in the AndroidManifest.xml file.

The following example is the code for the Notepad application, which is a basic example of Android. The components of an Intent Filter can be written to the Intent as well.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.notepad">
   <application android:icon="@drawable/app_notes"
           android:label="@string/app_name">

       <provider class=".NotePadProvider"
               android:authorities="com.google.provider.NotePad" />

       <activity class=".NotesList" android:label="@string/title_notes_list">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           <intent-filter>
               <action android:name="android.intent.action.VIEW" />
               <action android:name="android.intent.action.EDIT" />
               <action android:name="android.intent.action.PICK" />
               <category android:name="android.intent.category.DEFAULT" />
               <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
           </intent-filter>
           <intent-filter>
               <action android:name="android.intent.action.GET_CONTENT" />
               <category android:name="android.intent.category.DEFAULT" />
               <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
           </intent-filter>
       </activity>

       <activity class=".NoteEditor" android:label="@string/title_note">
           <intent-filter android:label="@string/resolve_edit">
               <action android:name="android.intent.action.VIEW" />
               <action android:name="android.intent.action.EDIT" />
               <category android:name="android.intent.category.DEFAULT" />
               <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
           </intent-filter>

           <intent-filter>
               <action android:name="android.intent.action.INSERT" />
               <category android:name="android.intent.category.DEFAULT" />
               <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
           </intent-filter>
       </activity>

       <activity class=".TitleEditor" android:label="@string/title_edit_title"
               android:theme="@android:style/Theme.Dialog">
           <intent-filter android:label="@string/resolve_title">
               <action android:name="com.android.notepad.action.EDIT_TITLE" />
               <category android:name="android.intent.category.DEFAULT" />
               <category android:name="android.intent.category.ALTERNATIVE" />
               <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
               <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
           </intent-filter>
       </activity>
   </application>
</manifest>

Share This Post

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

Latest Post