Intents and Intent Filters

Three of the core components of an application activities, services, and broadcast receivers are activated through messages, called intents. Intent messaging is a facility for late run-time binding between components in the same or different applications. The intent itself, an Intent object, is a passive data structure holding an abstract description of an operation to be performed or, often in the case of broadcasts, a description of something that has happened and is being announced. There are separate mechanisms for delivering intents to each type of component:

애플리케이션의 핵심 컴포넌트 세 개 - 액티비티, 서비스, 브로드캐스트 리시버 - 는 인텐트intent라고 불리는 메시지를 통해서 활성화된다. 인텐트 메세징은 동일 애플리케이션 내에 존재하는 컴포넌트 또는 다른 애플리케이션 내에 존재하는 컴포넌트들 간의 다소 더딘late(역주: start-up 시점이 아님)런타임 바인딩을 위한 도구이다. 인텐트 자체, 즉 인텐트 오브젝트는 수행되어야 하는 오퍼레이션에 대한 추상적인 설명을 보유하고 있는 데이터 구조이다 ? 또는, 브로드캐스트의 경우에는, 발생했고 그리고 공표된 어떤 것에 대한 표현이다. 각각의 컴포넌트 타입에 따라 인텐트를 전달하는 별도의 메커니즘이 존재한다.

  • 인텐트 오브젝트는 액티비티를 런치하거나 또는 어떤 것을 새로 수행할 이미 존재하는 액티비티를 얻기 위해서, Context.startActivity() 또는 Activity.startActivityForResult()에 전달된다. (이것은 또한 startActivityForResult()를 호출했던 액티비티에 정보를 반환하기 위해 Activity.setResult()에 전달될 수도 있다.)
  • 인텐트 오브젝트는 서비스를 초기화하거나 또는 실행중인 서비스에 새로운 지시를 전달하기 위해, Context.startService()에 전달된다. 유사하게, 인텐트는 호출하는 컴포넌트와 그것의 대상이 되는 서비스간의 커넥션을 확립하기 위해, Context.bindService()에 전달된다. 만약 서비스가 아직 실행되고 있지 않다면, 필요에 따라 서비스를 초기화 할 수 있다.

  • Context.sendBroadcast(), Context.sendOrderedBroadcast(), Context.sendStickyBroadcast() 와 같은 브로드캐스트 메쏘드들 중 어떤 것에 전달되는 인텐트 오브젝트는 그것에 관심을 갖는 모든 브로드캐스트 리시버들에게 전달된다. 많은 종류의 브로드캐스트들은 시스템 코드 내에서 만들어진다.

In each case, the Android system finds the appropriate activity, service, or set of broadcast receivers to respond to the intent, instantiating them if necessary. There is no overlap within these messaging systems: Broadcast intents are delivered only to broadcast receivers, never to activities or services. An intent passed to startActivity() is delivered only to an activity, never to a service or broadcast receiver, and so on.

각각의 경우에 있어서, 안드로이드 시스템은 인텐트에 응답할 적절한 액티비티, 서비스, 또는 브로드캐스트 리시버 집단을 찾으며, 필요하다면 그것들을 인스턴스화한다. 이러한 메세징 시스템 내에는 어떠한 오버랩도 존재하지 않는다; 브로드캐스트 인텐트는 브로드캐스트 리시버에게만 전달되며, 결코 액티비티나 서비스에는 전달되지 않는다. startActivity()에 전달된 인텐트는 오직 하나의 액티비티에만 전달되며 결코 서비스나 브로드캐스트 리시버, 기타 등등에게는 전달되지 않는다.

This document begins with a description of Intent objects. It then describes the rules Android uses to map intents to components how it resolves which component should receive an intent message. For intents that don't explicitly name a target component, this process involves testing the Intent object against intent filters associated with potential targets.

이 문서는 인텐트 오브젝트에 대한 설명으로 시작된다. 그것은 컴포넌트에 인텐트를 맵핑mapping하기 위해 안드로이드가 사용하는 규칙, 즉 어떤 컴포넌트가 인텐트 메시지를 수신해야 하는 지를 결정하는 방법을 설명한다. 인텐트가 전달되어야 하는 대상이 되는 컴포넌트를 명시적으로 지명하지 않는 경우에, 이 처리 과정은 잠재적인 대상들과 관련되어 있는 인텐트 필터에 대한 인텐트 오브젝트 테스트를 포함하게 된다.

Intent Objects

An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity). Principally, it can contain the following:

인텐트Intent 오브젝트는 하나의 정보 묶음이다. 그것은 (수행되어야 하는 액션과 그곳에서 처리해야 하는 데이터와 같이) 인텐트를 수신하게 되는 컴포넌트가 관심을 갖는 정보와 (인텐트를 제어해야 하는 컴포넌트의 카테고리와, 대상이 되는 액티비티를 런치하는 방법에 대한 지시와 같은) 안드로이드 시스템에 대한 추가적인 정보를 포함하고 있다. 기본적으로 그것은 다음과 같은 내용을 포함할 수 있다.

Component name
The name of the component that should handle the intent. This field is a ComponentName object a combination of the fully qualified class name of the target component (for example "com.example.project.app.FreneticActivity") and the package name set in the manifest file of the application where the component resides (for example, "com.example.project"). The package part of the component name and the package name set in the manifest do not necessarily have to match.

The component name is optional. If it is set, the Intent object is delivered to an instance of the designated class. If it is not set, Android uses other information in the Intent object to locate a suitable target see Intent Resolution, later in this document.

The component name is set by setComponent(), setClass(), or setClassName() and read by getComponent().

인텐트를 제어해야 하는 컴포넌트의 이름. 이 필드는 ComponentName 오브젝트 ? 타겟 컴포넌트 (예를 들어 “com.example.project.app.FreneticActivity”)의 전체 클래스 이름과 컴포넌트가 (예를 들어 “com.example.project”) 위치하는 곳으로 애플리케이션의 매니페스트 파일에서 설정된 패키지 이름의 조합이다. 컴포넌트 이름의 패키지 영역과 매니페스트에 설정된 패키지 이름은 반드시 일치할 필요는 없다.

컴포넌트 이름은 선택사항이다. 만약 그것이 지정되면, 인텐트 오브젝트는 지정된 클래스의 인스턴스에 전달된다. 만약 그것이 지정되지 않는다면, 안드로이드는 적당한 타겟을 찾아내기 위해 인텐트 오브젝트 내의 다른 정보를 이용한다 - 이 문서 다음에 나오는 “인텐트 확정” 섹션을 보라

컴포넌트 이름은 setComponent(), setClass(), 또는 setClassName()에 의해 설정되고 getComponent()에 의해 읽어진다.

Action
A string naming the action to be performed or, in the case of broadcast intents, the action that took place and is being reported. The Intent class defines a number of action constants, including these:
Constant Target component Action
ACTION_CALL activity Initiate a phone call.
ACTION_EDIT activity Display data for the user to edit.
ACTION_MAIN activity Start up as the initial activity of a task, with no data input and no returned output.
ACTION_SYNC activity Synchronize data on a server with data on the mobile device.
ACTION_BATTERY_LOW broadcast receiver A warning that the battery is low.
ACTION_HEADSET_PLUG broadcast receiver A headset has been plugged into the device, or unplugged from it.
ACTION_SCREEN_ON broadcast receiver The screen has been turned on.
ACTION_TIMEZONE_CHANGED broadcast receiver The setting for the time zone has changed.

See the Intent class description for a list of pre-defined constants for generic actions. Other actions are defined elsewhere in the Android API. You can also define your own action strings for activating the components in your application. Those you invent should include the application package as a prefix for example: "com.example.project.SHOW_COLOR".

The action largely determines how the rest of the intent is structured particularly the data and extras fields much as a method name determines a set of arguments and a return value. For this reason, it's a good idea to use action names that are as specific as possible, and to couple them tightly to the other fields of the intent. In other words, instead of defining an action in isolation, define an entire protocol for the Intent objects your components can handle.

The action in an Intent object is set by the setAction() method and read by getAction().

수행되어야 하는 액션을 지칭하는 문자열 ? 또는 브로드캐스트 인텐트의 경우에는, 얻게 되고 리포트 될 액션이다. 인텐트 클래스는 아래에 리스트된 것처럼, 많은 액션 상수들을 정의하고 있다.
상수 타겟 컴포넌트 액션
ACTION_CALL activity 전화를 걸어라.
ACTION_EDIT activity 사용자에게 편집할 데이터를 표시하라.
ACTION_MAIN activity 데이터 입력과 반환 결과 없이 태스크의 최초의 액티비티로써 액티비티를 실행하라.
ACTION_SYNC activity 모바일 디바이스의 데이터와 서버의 데이터를 동기화하라.
ACTION_BATTERY_LOW broadcast receiver 배터리가 부족하다는 경고.
ACTION_HEADSET_PLUG broadcast receiver 헤드셋이 디바이스에 연결 또는 분리되었다는 것.
ACTION_SCREEN_ON broadcast receiver 스크린이 켜졌다는 것.
ACTION_TIMEZONE_CHANGED broadcast receiver 타임존 설정이 바뀌었다는 것.

일반적인 액션들에 대한 미리 정의된 상수들의 리스트에 대해서는 인텐트 클래스에 대한 설명을 보라. 다른 액션들은 안드로이드 API의 다른 곳에서 정의된다. 여러분은 또한 여러분의 애플리케이션에 있는 컴포넌트를 활성화하기 위해 자기만의 액션 문자열들을 정의할 수 있다. 여러분이 만든 이런 것들은, 예를 들어 “com.example.project.SHOW_COLOR” 와 같이 접두어로서 애플리케이션 패키지를 포함해야 한다.

액션은 메쏘드 명이 매개변수들의 집합과 리턴 값을 결정하듯이, 인텐트의 나머지 부분 ? 특히, 데이터data와 엑스트라extras 필드 - 이 어떻게 구성되는지를 크기 결정한다. 이 이유 때문에, 가능한 한 상세하게 액션 이름을 사용하고, 그것들을 인텐트의 나머지 필드에 견고하게 결합하는 것이 좋다. 달리 표현해서, 독립된 형태로 액션을 정의하는 것보다 여러분의 컴포넌트가 제어할 수 있는 인텐트 오브젝트에 대한 전체 프로토콜을 정의하라.

인텐트 오브젝트의 액션은 setAction() 메쏘드에 의해 설정되고, getAction() 에 의해 읽어진다.

Data
The URI of the data to be acted on and the MIME type of that data. Different actions are paired with different kinds of data specifications. For example, if the action field is ACTION_EDIT, the data field would contain the URI of the document to be displayed for editing. If the action is ACTION_CALL, the data field would be a tel: URI with the number to call. Similarly, if the action is ACTION_VIEW and the data field is an http: URI, the receiving activity would be called upon to download and display whatever data the URI refers to.

When matching an intent to a component that is capable of handling the data, it's often important to know the type of data (its MIME type) in addition to its URI. For example, a component able to display image data should not be called upon to play an audio file.

In many cases, the data type can be inferred from the URI particularly content: URIs, which indicate that the data is located on the device and controlled by a content provider (see the separate discussion on content providers). But the type can also be explicitly set in the Intent object. The setData() method specifies data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it as both a URI and a MIME type. The URI is read by getData() and the type by getType().

처리되어야 하는 데이터에 대한 URI와 데이터의 MIME 타입. 서로 다른 액션들은 다른 종류의 데이터 명세와 한 조를 이룬다. 예를 들어 만일 액션 필드가 ACTION_EDIT라면, 데이터 필드는 편집을 위해 보여지게 될 문서의 URI를 포함할 것이다. 만일 액션이 ACTION_CALL 이라면, 데이터 필드는 통화해야 할 번호를 가진 tel: URI가 될 것이다, 비슷하게, 만일 액션이 ACTION_VIEW이고 데이터 필드가 http: URI라면, 그것을 수신하는 액티비티는 다운로드를 수행할 것이고, URI가 가리키는 데이터를 보여줄 것이다.

인텐트를 그 데이터를 처리할 능력이 있는 컴포넌트에 매칭할 때, 가끔 그 URI에 추가해서 그 데이터의 타입(그것의 MIME 타입)을 아는 것이 중요하다. 예를 들어 이미지 데이터를 보여줄 수 있는 컴포넌트가 오디오 파일을 재생하기 위해서 호출되어서는 안된다.

많은 경우에 있어서, 데이터 타입은 URI로부터 추측될 수 있다 - 특히 디바이스상에 존재하는 데이터를 가리키고 컨텐트 프로바이더(7장. “컨텐트 프로바이더”를 보라)에 의해 제어되는 content: URI들이 그렇다. 하지만 데이터 타입 또한 명시적으로 인텐트 오브젝트 내에 지정될 수도 있다. setData() 메쏘드는 URI만 사용해서 데이터를 지정하며, setType()은 MIME 타입으로만 그것을 지정하며, 그리고 setDataAndType()은 URI와 MIME 타입 둘 다에 의해 그것을 지정한다. URI는 getData()에 의해 읽혀지게 되고, 타입은 getType()에 의해 읽혀진다.

Category
A string containing additional information about the kind of component that should handle the intent. Any number of category descriptions can be placed in an Intent object. As it does for actions, the Intent class defines several category constants, including these:
Constant Meaning
CATEGORY_BROWSABLE The target activity can be safely invoked by the browser to display data referenced by a link for example, an image or an e-mail message.
CATEGORY_GADGET The activity can be embedded inside of another activity that hosts gadgets.
CATEGORY_HOME The activity displays the home screen, the first screen the user sees when the device is turned on or when the HOME key is pressed.
CATEGORY_LAUNCHER The activity can be the initial activity of a task and is listed in the top-level application launcher.
CATEGORY_PREFERENCE The target activity is a preference panel.

See the Intent class description for the full list of categories.

The addCategory() method places a category in an Intent object, removeCategory() deletes a category previously added, and getCategories() gets the set of all categories currently in the object.

인텐트를 제어해야 하는 컴포넌트의 종류에 대한 추가적인 정보를 포함하는 문자열. 인텐트 오브젝트 내에는 임의의 수의 카테고리들이 있을 수 있다. 액션에 대해서 그러했듯이, 인텐트 클래스는 다음과 같은 것을 포함하는 몇 가지의 카테고리 상수를 정의하고 있다.
상 수 의미하는 바
CATEGORY_BROWSABLE 타겟 액티비티는 링크에 의해 참조되는 데이터(예를 들어 이미지나 이메일 메시지)를 보여주기 위해 브라우저에 의해 안전하게 호출될 수 있다.
CATEGORY_GADGET 액티비티는 가젯들을 보유할 수 있는 다른 액티비티 내에 임베딩될수 있다.
CATEGORY_HOME 액티비티는 홈 화면을 보여준다. 디바이스가 켜질 때나 HOME 키가 눌렸을 때, 사용자가 보게되는 첫 번째 화면.
CATEGORY_LAUNCHER 액티비티는 하나의 태스크에서 최초의 액티비티가 될 수 있으며, 최상위 계층의 애플리케이션 런처에 리스트된다.
CATEGORY_PREFERENCE 타겟 액티비티는 설정 패널이다.

전체 카테고리 리스트에 대해서는 인텐트 클래스 설명을 보라.

addCategory() 메쏘드는 인텐트 오브젝트에 카테고리를 추가한다. remove Category()는 이전에 추가된 카테고리를 삭제하며, getCategories()는 해당 오브젝트 안에 있는 현재의 모든 카테고리들을 얻는다.

Extras
Key-value pairs for additional information that should be delivered to the component handling the intent. Just as some actions are paired with particular kinds of data URIs, some are paired with particular extras. For example, an ACTION_TIMEZONE_CHANGED intent has a "time-zone" extra that identifies the new time zone, and ACTION_HEADSET_PLUG has a "state" extra indicating whether the headset is now plugged in or unplugged, as well as a "name" extra for the type of headset. If you were to invent a SHOW_COLOR action, the color value would be set in an extra key-value pair.

The Intent object has a series of put...() methods for inserting various types of extra data and a similar set of get...() methods for reading the data. These methods parallel those for Bundle objects. In fact, the extras can be installed and read as a Bundle using the putExtras() and getExtras() methods.

추가적인 정보에 대한 키-값 쌍key-value pairs이 인텐트를 제어하는 컴포넌트에 전달되기도 한다. 약간의 액션들이 특별한 종류의 데이터 URI들과 한 조를 이루듯이, 약간의 것들은 특정한 엑스트라들과 한 조를 이룬다. 예를 들어 ACTION_TIMEZONE_CHANGED 인텐트는 새로운 시간대를 나타내는 “time-zone” 엑스트라를 가지며, ACTION_HEADSET_PLUG는 헤드셋의 타입에 대한 “name” 엑스트라뿐만 아니라, 헤드셋이 방금 연결되었는지 아니면 제거되었는지를 가리키는 “state” 엑스트라를 가진다. 만약 여러분이 SHOW_COLOR 액션을 만들었다면, 컬러 값이 엑스트라 키-값 쌍key-value pairs안에 지정될 수도 있다.

인텐트 오브젝트에는 엑스트라 데이터의 다양한 타입을 추가하는 일련의 put...() 메쏘드를 가지며, 해당 데이터를 읽어오기 위한 일련의 get...() 메쏘드를 가진다. 그러한 메쏘드들은 번들 오브젝트들에 대한 메쏘드들과 함께 한다. 실제로, 그러한 엑스트라는 putExtras()와 getExtras() 메쏘드들을 사용하여 하나의 번들로써 설치되거나 읽혀질 수도 있다.

Flags
Flags of various sorts. Many instruct the Android system how to launch an activity (for example, which task the activity should belong to) and how to treat it after it's launched (for example, whether it belongs in the list of recent activities). All these flags are defined in the Intent class.
다양한 종류의 플래그. 많은 것들이 안드로이드 시스템에 의한 액티비티 런치 방법(예를 들어 액티비티가 어떤 태스크에 속해야 하는지)과 런치 후 액티비티를 다루는 방법(예를 들어 최근 액티비티 리스트에 그것이 속하는 지의 여부)을 지시한다. 이러한 모든 플래그들은 인텐트 클래스에서 정의된다.

The Android system and the applications that come with the platform employ Intent objects both to send out system-originated broadcasts and to activate system-defined components. To see how to structure an intent to activate a system component, consult the list of intents in the reference.

안드로이드 시스템과 안드로이드 플랫폼의 애플리케이션들 모두는 시스템에서 발생된 브로드캐스트를 발송하고, 시스템이 정의한 컴포넌트를 활성화 하기 위해 인텐트 오브젝트를 사용한다. 시스템 컴포넌트를 활성화하기 위한 인텐트를 구조화하는 방법을 보기 위해서는 레퍼런스에 있는 인텐트 목록을 참고하라.

Intent Resolution

Intents can be divided into two groups:

인텐트는 두 그룹으로 나눠질 수 있다.

  • Explicit intents designate the target component by its name (the component name field, mentioned earlier, has a value set). Since component names would generally not be known to developers of other applications, explicit intents are typically used for application-internal messages such as an activity starting a subordinate service or launching a sister activity.
  • Implicit intents do not name a target (the field for the component name is blank). Implicit intents are often used to activate components in other applications.

  • 명시적인(Explicit) 인텐트는 타겟 컴포넌트를 그것의 이름(앞서 언급되었던 컴포넌트 이름 필드에 값이 설정되어 있다)으로 지정한다. 컴포넌트 이름은 일반적으로 다른 애플리케이션의 개발자에게 알려질 수 없기 때문에, 명시적인 인텐트는 전형적으로 (액티비티가 자신에 부수적인 서비스를 실행시키거나, 또는 동격의 액티비티를 실행시키는 것과 같이) 애플리케이션 내부 메시지들을 위해 사용된다.
  • 암시적인(Implicit) 인텐트는 타겟 이름을 지정하지 않는다(컴포넌트 이름 필드는 비어있다). 암시적인 인텐트는 다른 애플리케이션의 컴포넌트를 활성화하기 위해 자주 사용된다.

Android delivers an explicit intent to an instance of the designated target class. Nothing in the Intent object other than the component name matters for determining which component should get the intent.

안드로이드는 지정된 타겟 클래스의 인스턴스에 명시적explicit 인텐트를 전달한다. 인텐트 오브젝트에서 그 인텐트를 얻어야 하는 컴포넌트를 결정함에 있어서, 컴포넌트 이름보다 더 중요한 것은 아무것도 없다.

A different strategy is needed for implicit intents. In the absence of a designated target, the Android system must find the best component (or components) to handle the intent a single activity or service to perform the requested action or the set of broadcast receivers to respond to the broadcast announcement. It does so by comparing the contents of the Intent object to intent filters, structures associated with components that can potentially receive intents. Filters advertise the capabilities of a component and delimit the intents it can handle. They open the component to the possibility of receiving implicit intents of the advertised type. If a component does not have any intent filters, it can receive only explicit intents. A component with filters can receive both explicit and implicit intents.

하나의 다른 전략이 암시적Implicit 인텐트를 위해서 필요하다. 지정된 타겟이 없을 경우에, 안드로이드 시스템은 해당 인텐트를 처리할 최상의 컴포넌트(혹은 컴포넌트들), 즉 요청된 액션을 수행할 하나의 액티비티 혹은 서비스, 또는 브로드캐스트 통보에 응답할 보로드캐스트 리시버들의 집합을 찾아야만 한다. 이것은 인텐트를 잠재적으로 수신할 수 있는 컴포넌트들과 결합된 구조인 인텐트 필터와 인텐트 오브젝트 내의 내용들을 비교하는 것에 의해 이루어진다. 필터들은 컴포넌트의 기능을 알리며 처리할 수 있는 인텐트의 범위를 정한다. 이것들은 해당 컴포넌트에게 자신이 제시한 유형과 연관된 암시적Implicit 인텐트를 수신할 수 있는 가능성을 열어준다. 만약 컴포넌트가 어떤 인텐트 필터도 가지고 있지 않다면, 그것은 명시적 인텐트만을 받을 수 있다. 필터를 가진 컴포넌트는 명시적거나 암시적인 인텐트 모두를 수신할 수 있다.

Only three aspects of an Intent object are consulted when the object is tested against an intent filter:

오브젝트가 인텐트 필터에 대한 테스트가 이루어질 때, 인텐트 오브젝트의 세 가지 측면이 검토된다.

action
data (both URI and data type)
category

action data (URI와 데이터 타입 두가지 모두) category

The extras and flags play no part in resolving which component receives an intent.

엑스트라와 플래그는 어떤 컴포넌트가 인텐트를 수신할 것인가를 결정하는데 있어서 아무런 역할도 하지 않는다.

Intent filters

To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have one or more intent filters. Each filter describes a capability of the component, a set of intents that the component is willing to receive. It, in effect, filters in intents of a desired type, while filtering out unwanted intents but only unwanted implicit intents (those that don't name a target class). An explicit intent is always delivered to its target, no matter what it contains; the filter is not consulted. But an implicit intent is delivered to a component only if it can pass through one of the component's filters.

액티비티, 서비스, 그리고 브로드캐스트 리시버는 시스템에 그들이 처리할 수 있는 암시적implicit 인텐트들이 어떤 것인가를 알려주기 위해, 하나 이상의 인텐트 필터를 가질 수 있다. 각각의 필터는 컴포넌트의 처리능력, 즉 컴포넌트가 수신하고자 하는 인텐트들의 집합을 기술한다. 그 각 필터는 실제로 원하지 않았던 인텐트를 배제함으로써, 필요한 타입의 인텐트들만을 걸러낸다. 하지만 그들이 배제한 것은 단지 타겟 클래스 이름을 지칭하지 않은 암시적implicit 인텐트일 뿐이다. 명시적explicit 인텐트는 그것이 무엇을 포함하든 상관없이 항상 그것의 타겟에 전달된다. 이 경우 필터는 고려되지 않는다. 그러나 암시적implicit 인텐트는 컴포넌트 필터 중 한 개를 통과할 수 있다면, 해당 컴포넌트에게 전달되어진다.

A component has separate filters for each job it can do, each face it can present to the user. For example, the NoteEditor activity of the sample Note Pad application has two filters one for starting up with a specific note that the user can view or edit, and another for starting with a new, blank note that the user can fill in and save. (All of Note Pad's filters are described in the Note Pad Example section, later.)

컴포넌트는 그것들이 할 수 있는 각각의 작업, 즉 사용자에게 그것이 제시할 수 있는 각각의 모습 별로 별도의 필터를 소유할 수 있다. 예를 들어 샘플 노트패드NotePad 애플리케이션의 NoteEditor 액티비티는 두 개의 필터를 가진다. 사용자가 보거나 편집할 수 있는 특정 노트를 가지고 시작되는 것 하나와 사용자가 그 안에 기입하고 저장할 수 있는 신규 또는 빈 노트를 가지고 시작되는 다른 하나가 있다. (모든 Note Pad 필터는 나중에 Note Pad 예제 섹션에서 설명된다.)

An intent filter is an instance of the IntentFilter class. However, since the Android system must know about the capabilities of a component before it can launch that component, intent filters are generally not set up in Java code, but in the application's manifest file (AndroidManifest.xml) as <intent-filter> elements. (The one exception would be filters for broadcast receivers that are registered dynamically by calling Context.registerReceiver(); they are directly created as IntentFilter objects.)

인텐트 필터는 IntentFilter 클래스에 대한 하나의 인스턴스이다. 하지만 안드로이드 시스템은 해당 컴포넌트를 실행하기 전에 컴포넌트의 기능에 대해 알아야 하기 때문에, 인텐트 필터는 일반적으로 Java 코드 내부가 아닌, 애플리케이션의 매니페스트 파일인 AndroidManifest.xml의 <intent-filter> 애트리뷰트를 사용해서 정의된다(브로드캐스트 리시버에 한하여, Context.registerReceiver()의 호출을 통해 동적으로 등록되는 필터가 하나의 예외이다; 그것들은 IntentFilter 오브젝트로 직접 생성된다).

A filter has fields that parallel the action, data, and category fields of an Intent object. An implicit intent is tested against the filter in all three areas. To be delivered to the component that owns the filter, it must pass all three tests. If it fails even one of them, the Android system won't deliver it to the component at least not on the basis of that filter. However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another.

필터는 인텐트 오브젝트의 액션, 데이터, 카테고리를 나열하는 필드들을 가진다. 암시적implicit 인텐트는 세 개의 모든 영역의 필터들에 대해 테스트된다. 그 필터를 소유하고 있는 컴포넌트에 인텐트가 전달되게 하기 위해서는, 그것은 세 개의 모든 테스트가 통과되어야 한다. 만약 그것들 중 하나라도 실패한다면, 안드로이드 시스템은 그 컴포넌트에 인텐트를 전달하지 않을 것이다. 적어도 그 필터의 기준하에서는 안된다. 그러나 컴포넌트는 복수의 인텐트 필터를 가질 수 있기 때문에, 컴포넌트의 필터들 중 하나를 통과하지 못했던 인텐트가 또 다른 필터를 통과할 수도 있다.

Each of the three tests is described in detail below:

세 개의 테스트 각각이 아래에서 상세하게 설명된다.

Action test
An <intent-filter> element in the manifest file lists actions as <action> subelements. For example:
<intent-filter . . . >
    <action android:name="com.example.project.SHOW_CURRENT" />
    <action android:name="com.example.project.SHOW_RECENT" />
    <action android:name="com.example.project.SHOW_PENDING" />
    . . .
</intent-filter>

As the example shows, while an Intent object names just a single action, a filter may list more than one. The list cannot be empty; a filter must contain at least one <action> element, or it will block all intents.

To pass this test, the action specified in the Intent object must match one of the actions listed in the filter. If the object or the filter does not specify an action, the results are as follows:

  • If the filter fails to list any actions, there is nothing for an intent to match, so all intents fail the test. No intents can get through the filter.
  • On the other hand, an Intent object that doesn't specify an action automatically passes the test as long as the filter contains at least one action.

매니페스트 파일의 <intent-filter> 엘리먼트는 <action> 서브엘리먼트로 액션들을 리스트한다. 예를 들어 아래와 같다.
<intent-filter . . . >
    <action android:name="com.example.project.SHOW_CURRENT" />
    <action android:name="com.example.project.SHOW_RECENT" />
    <action android:name="com.example.project.SHOW_PENDING" />
    . . .
</intent-filter>

예제에서 보이듯이, 인텐트 오브젝트는 단지 하나의 액션을 지정하지만, 필터는 하나 이상의 액션을 지정할 수도 있다. 액션 리스트는 비어 있어서는 안된다. 필터는 적어도 하나의 <action> 엘리먼트를 포함해야 한다. 그렇지 않다면, 그것은 모든 인텐트들을 차단할 것이다.

이 테스트를 통과하기 위해 인텐트 오브젝트 내에 명시된 액션은, 필터에 나열된 액션들 중의 하나와 일치해야 한다. 만약 오브젝트 또는 필터가 액션을 명시하지 않았다면, 그 결과는 아래와 같다.

  • 만일 필터가 어떤 액션도 나열하지 않았다면, 인텐트에 일치할 수 있는 어떤 것도 없다. 그러므로 모든 인텐트는 테스트에 실패한다. 어떤 인텐트도 해당 필터를 통해 얻을 수 없다.
  • 반면에, 액션을 명시하지 않은 인텐트 오브젝트는 자동으로 테스트를 통과한다 ? 그 필터가 적어도 하나의 액션을 포함하고 있는 한 그렇다. (역주 : 액션을 명시하지 않은 인텐트 오브젝트 역시 필터 테스트를 통과하지 못하는 것으로 확인되었으나, 추후 좀 더 상세한 검토가 필요한 듯하다.)

Category test
An <intent-filter> element also lists categories as subelements. For example:
<intent-filter . . . >
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    . . .
</intent-filter>

Note that the constants described earlier for actions and categories are not used in the manifest file. The full string values are used instead. For instance, the "android.intent.category.BROWSABLE" string in the example above corresponds to the CATEGORY_BROWSABLE constant mentioned earlier in this document. Similarly, the string "android.intent.action.EDIT" corresponds to the ACTION_EDIT constant.

For an intent to pass the category test, every category in the Intent object must match a category in the filter. The filter can list additional categories, but it cannot omit any that are in the intent.

In principle, therefore, an Intent object with no categories should always pass this test, regardless of what's in the filter. That's mostly true. However, with one exception, Android treats all implicit intents passed to startActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters. (Filters with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings are the exception. They mark activities that begin new tasks and that are represented on the launcher screen. They can include "android.intent.category.DEFAULT" in the list of categories, but don't need to.) See Using intent matching, later, for more on these filters.)

<intent-filter> 엘리먼트는 또한 서브엘리먼트로 카테고리들을 리스트 한다. 예를 들어 아래와 같다.
<intent-filter . . . >
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    . . .
</intent-filter>

이전에 설명되었던, 액션과 카테고리에 대한 상수들은 매니페스트 파일에서는 사용되지 않는 다는 것에 유의하라. 대신 전체 문자열 값이 사용된다. 예를 들어 위에 예제에 있는 “android.intent.category.BROWSABLE” 스트링은 앞서 이 문서에서 언급되었던 CATEGORY_BROWSABLE 상수에 대응한다. 비슷하게 “android.intent.action.EDIT”는 문자열은 ACTION_EDIT에 대응한다.

인텐트가 카테고리 테스트를 통과하기 위해서는 인텐트 오브젝트 안의 모든 카테고리가 필터에 있는 카테고리와 일치해야 한다. 필터는 추가적으로 카테고리들을 나열할 수 있지만, 그것은 인텐트 안에 있는 그 어떤 것도 생략할 수는 없다.

그러므로 원칙적으로, 카테고리를 가지지 않은 인텐트 오브젝트는 필터에 무엇이 있든 관계 없이 항상 이 테스트을 통과해야 한다. 그것은 대체로 사실이다. 하지만 하나의 예외가 있는데, 그것은 안드로이드가 startActivity()에 전달되는 모든 암시적implicit 인텐트가 마치 적어도 하나의 카테고리인 “android.intent.category.DEFAULT”(CATEGORY_DEFAULT 상수)를 포함하고 있는 것처럼 취급된다는 것이다. 그러므로 암시적implicit 인텐트를 수신하고자 하는 액티비티는 그들의 인텐트 필터에서 “android.intent.category.DEFAULT”를 포함해야 한다(단, “android.intent.action.MAIN”과 “android.intent.category.LAUNCHER”가 설정된 필터는 예외다. 이것들은 액티비티를 신규 태스크로 시작시키고 런처 스크린에 표시되도록 마크한다. 그것들은 카테고리 리스트에 “android.intent.category.DEFAULT”를 포함할 수는 있지만, 필요치는 않는다). 이 필터에 대한 상세한 것은 이후 나오는 “인텐트 매칭 사용하기”를 나중에 보라.

Data test
Like the action and categories, the data specification for an intent filter is contained in a subelement. And, as in those cases, the subelement can appear multiple times, or not at all. For example:
<intent-filter . . . >
    <data android:mimeType="video/mpeg" android:scheme="http" . . . /> 
    <data android:mimeType="audio/mpeg" android:scheme="http" . . . />
    . . .
</intent-filter>

Each <data> element can specify a URI and a data type (MIME media type). There are separate attributes scheme, host, port, and path for each part of the URI:

scheme://host:port/path

For example, in the following URI,

content://com.example.project:200/folder/subfolder/etc

the scheme is "content", the host is "com.example.project", the port is "200", and the path is "folder/subfolder/etc". The host and port together constitute the URI authority; if a host is not specified, the port is ignored.

Each of these attributes is optional, but they are not independent of each other: For an authority to be meaningful, a scheme must also be specified. For a path to be meaningful, both a scheme and an authority must be specified.

When the URI in an Intent object is compared to a URI specification in a filter, it's compared only to the parts of the URI actually mentioned in the filter. For example, if a filter specifies only a scheme, all URIs with that scheme match the filter. If a filter specifies a scheme and an authority but no path, all URIs with the same scheme and authority match, regardless of their paths. If a filter specifies a scheme, an authority, and a path, only URIs with the same scheme, authority, and path match. However, a path specification in the filter can contain wildcards to require only a partial match of the path.

The type attribute of a <data> element specifies the MIME type of the data. It's more common in filters than a URI. Both the Intent object and the filter can use a "*" wildcard for the subtype field for example, "text/*" or "audio/*" indicating any subtype matches.

The data test compares both the URI and the data type in the Intent object to a URI and data type specified in the filter. The rules are as follows:

  1. An Intent object that contains neither a URI nor a data type passes the test only if the filter likewise does not specify any URIs or data types.
  2. An Intent object that contains a URI but no data type (and a type cannot be inferred from the URI) passes the test only if its URI matches a URI in the filter and the filter likewise does not specify a type. This will be the case only for URIs like mailto: and tel: that do not refer to actual data.

  3. An Intent object that contains a data type but not a URI passes the test only if the filter lists the same data type and similarly does not specify a URI.

  4. An Intent object that contains both a URI and a data type (or a data type can be inferred from the URI) passes the data type part of the test only if its type matches a type listed in the filter. It passes the URI part of the test either if its URI matches a URI in the filter or if it has a content: or file: URI and the filter does not specify a URI. In other words, a component is presumed to support content: and file: data if its filter lists only a data type.

액션과 카테고리와 같이, 인텐트 필터에 대한 데이터 명세가 서브엘리먼트에 포함된다. 그리고 그런 경우와 같이 서브엘리먼트는 여러 번 나타날 수도 있고, 전혀 나타나지 않을 수도 있다. 예를 들어 아래와 같다.
<intent-filter . . . >
    <data android:mimeType="video/mpeg" android:scheme="http" . . . /> 
    <data android:mimeType="audio/mpeg" android:scheme="http" . . . />
    . . .
</intent-filter>

각각의 <data> 엘리먼트는 URI와 데이터 타입(MIME 미디어 타입)을 지정할 수 있다. 그곳에는 URI의 각 영역에 대한 별도의 애트리뷰트인 schema(스키마), host(호스트), port(포트), 그리고 path(경로)가 있다.

scheme://host:port/path

예를 들어 아래의 URI에서

content://com.example.project:200/folder/subfolder/etc

scheme은 “content”이고, host는 “com.example.project”이며, port는 “200”, 그리고 path는 “folder/subfolder/etc” 이다. host와 port는 함께 URI authority(당국)을 구성한다. 만약 host가 지정되지 않는다면, port는 무시된다.

이러한 각각의 애트리뷰트는 선택사항이다. 그러나 그것들은 서로 독립적이지는 않다. Authority가 의미를 가지기 위해서는 scheme 또한 명시되어야 한다. path가 의미를 가지기 위해서는 sheme과 authority 두 가지 모두가 명시되어야 한다.

인텐트 오브젝트에 있는 URI가 필터에 있는 URI 명세와 비교될 때, 그것은 실제로 필터에서 언급된 URI의 부분들에 대해서만 비교된다. 예를 들어 만약 필터가 scheme만을 명시한다면, 해당 scheme를 보유한 모든 URI는 필터와 일치한다. 만약 필터가 path없이 scheme과 authority를 명시한다면, 그들의 path와 관계없이, 같은 scheme과 authority를 가지는 모든 URI가 일치한다. 만약 필터가 scheme, authority, path를 명시한다면, 같은 scheme, authority, 그리고 path를 가지는 URI가 일치한다. 그러나 필터에서 path 명시는 path의 부분적 일치만을 요구하기 위해 와일드카드(*)를 포함시킬 수 있다.

<data> 엘리먼트 type 애트리뷰트는 데이터의 MIME 타입을 명시한다. 그것은 필터에서 URI보다는 보다 보편적이다. 인텐트 오브젝트와 필터는 둘 다 하위타입 필드에 대해서 “*” 와일드카드를 사용할 수 있다. 예를 들어 어떤 하위타입이든 일치하는 것을 지칭하는 “text/*” 또는 “audio/*” 를 사용할 수 있다.

데이터 테스트는 인텐트 오브젝트 내에 있는 URI와 데이터 타입을 필터에 명시된 URI와 데이터 타입과 비교한다. 규칙은 다음과 같다:

  1. URI와 데이터 타입 모두를 포함하고 있지 않은 인텐트 오브젝트는, 필터가 마찬가지로 어떤 URI와 데이터 타입도 명시하지 않는 경우에 한하여 테스트를 통과한다.
  2. URI를 포함하고 있지만 데이터 타입을 포함하지 않은 (그리고 URI로부터 데이터 타입이 추측될 수 없는) 인텐트 오브젝트는 그 URI가 필터의 URI와 일치하고, 필터가 마찬가지로 타입을 명시하지 않는 경우에 한하여 테스트를 통과한다. 이것은 실질적인 데이터를 참조하지 않는 mailto: 와 tel: 같은 URI에 대한 경우일 것이다.

  3. 데이터 타입을 포함하지만, URI를 포함하지 않은 인텐트 오브젝트는 필터가 동일한 데이터 타입을 리스트하고 있고, 비슷하게 URI를 명시하지 않는 경우에 한하여 테스트를 통과한다.

  4. URI와 데이터 타입 모두를 포함하거나 데이터 타입이 없더라도 그것이 URI로부터 추측될 수 있는 경우의 인텐트 오브젝트는, 그것의 type이 필터에 나열된 type과 일치하는 경우에 한하여 데이터 타입 영역에 대한 테스트를 통과한다. 그리고 만약 인텐트의 URI가 필터 안의 URI와 일치하거나, 그것이 content: 또는 file: 형식의 URI이고 필터가 URI를 명시하고 있지 않는 경우에 한하여 URI 영역에 대한 테스트를 통과한다. 바꿔 말하면, 그것의 필터가 단지 하나의 데이터 타입을 나열하고 있다면, 컴포넌트는 content: 과 file: 데이터를 지원하는 것으로 간주된다.

If an intent can pass through the filters of more than one activity or service, the user may be asked which component to activate. An exception is raised if no target can be found.

만약 인텐트가 하나 이상의 액티비티 혹은 서비스의 필터를 통과할 수 있다면, 사용자에게 어떤 컴포넌트가 활성화되어야 하는지 물어지게 된다. 만약 어떤 타겟도 발견될 수 없다면 예외exception가 발생한다.

Common cases

The last rule shown above for the data test, rule (d), reflects the expectation that components are able to get local data from a file or content provider. Therefore, their filters can list just a data type and do not need to explicitly name the content: and file: schemes. This is a typical case. A <data> element like the following, for example, tells Android that the component can get image data from a content provider and display it:

위에서 보여진 데이터 테스트 대한 마지막 규칙인 규칙 D는 컴포넌트들이 파일 또는 컨텐트 프로바이더로부터 로컬 데이터를 얻을 수 있다는 기대를 반영한다. 그러므로 그 컴포넌트들의 필터는 단지 데이터 타입을 리스트할 수 있기 때문에 명시적으로 content: 와 file: 스키마scheme 이름을 필요로 하지 않는다. 이것은 전형적인 경우다. 예를 들어 다음과 같은 <data> 엘리먼트는 그 컴포넌트가 컨텐트 프로바이더로부터 이미지 데이터를 얻을 수 있고 그것을 표시할 수 있다는 것을 안드로이드에게 알려준다:

<data android:mimeType="image/*" />

Since most available data is dispensed by content providers, filters that specify a data type but not a URI are perhaps the most common.

대부분의 사용가능한 데이터가 컨텐트 프로바이더에 의해 분배되기 때문에, URI 이외에 데이터 타입을 지정하는 필터는 아마 가장 보편적이다.

Another common configuration is filters with a scheme and a data type. For example, a <data> element like the following tells Android that the component can get video data from the network and display it:

또 다른 보편적인 설정은 스키마scheme와 데이터 타입을 가지는 필터이다. 예를 들어 다음과 같은 <data> 엘리먼트는 컴포넌트가 네트워크로부터 비디오 데이터를 얻고 표시할 수 있다는 것을 안드로이드에게 말한다:

<data android:scheme="http" android:type="video/*" />

Consider, for example, what the browser application does when the user follows a link on a web page. It first tries to display the data (as it could if the link was to an HTML page). If it can't display the data, it puts together an implicit intent with the scheme and data type and tries to start an activity that can do the job. If there are no takers, it asks the download manager to download the data. That puts it under the control of a content provider, so a potentially larger pool of activities (those with filters that just name a data type) can respond.

예를 들어 사용자가 웹 페이지의 하나의 링크를 따라갈 때, 브라우저 애플리케이션이 무엇을 하는지 생각해보라. 그것은 먼저 데이터를 표시하려고 시도한다(만약 링크가 HTML 페이지라면 그것이 할 수 있듯이). 만약 그것이 데이터를 표시할 수 없다면, 그것은 암시적implicit 인텐트에 스키마scheme와 데이터 타입을 함께 넣은 다음 그 작업을 할 수 있는 액티비티를 시작시키려고 시도할 것이다. 만약 거기에 인텐트를 받을 액티비티가 없다면, 그것은 다운로드 매니저에게 데이터를 다운로드할 것을 요청할 것이다. 그것은 컨텐트 프로바이더의 제어 하에 놓인다. 그러므로 잠재적으로 더 많은 액티비티들(단지 데이터 타입만을 명시하는 필터를 가진 것들)의 풀pool이 응답할 수 있다.

Most applications also have a way to start fresh, without a reference to any particular data. Activities that can initiate applications have filters with "android.intent.action.MAIN" specified as the action. If they are to be represented in the application launcher, they also specify the "android.intent.category.LAUNCHER" category:

대부분의 애플리케이션은 또한 어떤 특정 데이터를 참조하지 않고 새롭게 시작하는 방법을 가진다. 애플리케이션을 초기화할 수 있는 액티비티들은 액션으로 “android.intent.action.MAIN”이 지정된 필터를 가진다. 만약 그들이 애플리케이션 런처에서 보여지게 된다면, 그들은 또한 “android.intent.category.LAUNCHER” 카테고리를 지정하고 있다.

<intent-filter . . . >
    <action android:name="code android.intent.action.MAIN" />
    <category android:name="code android.intent.category.LAUNCHER" />
</intent-filter>

Using intent matching

Intents are matched against intent filters not only to discover a target component to activate, but also to discover something about the set of components on the device. For example, the Android system populates the application launcher, the top-level screen that shows the applications that are available for the user to launch, by finding all the activities with intent filters that specify the "android.intent.action.MAIN" action and "android.intent.category.LAUNCHER" category (as illustrated in the previous section). It then displays the icons and labels of those activities in the launcher. Similarly, it discovers the home screen by looking for the activity with "android.intent.category.HOME" in its filter.

인텐트는 활성화할 타겟 컴포넌트를 찾기 위해서 뿐만아니라, 또한 디바이스 상의 컴포넌트의 집합에 관한 어떤 것을 찾기 위해 인텐트 필터와 일치되어야 한다. 예를 들어 안드로이드 시스템은 “android.intent.action.MAIN” 액션과 “android.intent.category.LAUNCHER” 카테고리(이전 섹션에서 설명된 것과 같이)를 지정하는 인텐트 필터를 가진 모든 액티비티를 찾아냄으로써, 사용자가 실행시킬 수 있는 애플리케이션을 보여주는 최상위 스크린인 애플리케이션 런처를 구성한다. 그런 다음 시스템에 그 액티비티들의 아이콘과 라벨을 표시한다. 비슷하게, 그 시스템은 필터 안에 “android.intent.category.HOME”을 가지는 액티비티를 찾음으로써 홈스크린을 발견한다.

Your application can use intent matching is a similar way. The PackageManager has a set of query...() methods that return all components that can accept a particular intent, and a similar series of resolve...() methods that determine the best component to respond to an intent. For example, queryIntentActivities() returns a list of all activities that can perform the intent passed as an argument, and queryIntentServices() returns a similar list of services. Neither method activates the components; they just list the ones that can respond. There's a similar method, queryBroadcastReceivers(), for broadcast receivers.

여러분의 애플리케이션은 비슷한 방법으로 일치하는 인텐트를 사용할 수 있다. 패키지 매니저PackageManager는 특정 인텐트를 수용할 수 있는 모든 컴포넌트들을 리턴해 주는 query...() 메쏘드 집합과 인텐트에 응답할 최고의 컴포넌트를 결정하는 유사한 일련의 resolve...() 메쏘드들이 있다. 예를 들어 queryIntentActivities()는 아규먼트로 전달된 인텐트를 수행할 수 있는 모든 액티비티 리스트를 리턴하며, queryIntentServices()는 유사한 서비스 리스트를 리턴한다. 위의 모든 메쏘드들은 컴포넌트를 활성화시키지는 않는다. 그것들은 다만 응답할 수 있는 컴포넌트들을 리스트할 뿐이다. 비슷한 방법으로 브로드캐스트 리시버에 대한 queryBroadcastReceivers()가 있다.

Note Pad Example

The Note Pad sample application enables users to browse through a list of notes, view details about individual items in the list, edit the items, and add a new item to the list. This section looks at the intent filters declared in its manifest file. (If you're working offline in the SDK, you can find all the source files for this sample application, including its manifest file, at <sdk>/samples/NotePad/index.html. If you're viewing the documentation online, the source files are in the Tutorials and Sample Code section here.)

노트 패드 샘플 애플리케이션은 사용자가 노트 목록을 열람하고, 목록에 있는 개별 아이템을 상세히 보고, 아이템을 수정하고, 그리고 목록에 신규 아이템을 추가할 수 있게 한다. 이 섹션은 그것의 매니페스트 파일에 선언된 인텐트 필터들을 살펴본다. (만약 여러분이 SDK에서 오프라인 작업을 하고 있다면, 여러분은 <sdk>/samples/NotePad/index.html에서 그것의 매니페스트 파일을 포함해서 샘플 애플리케이션에 대한 모든 소스 파일들을 발견할 수 있다. 만약 여러분이 문서를 온라인으로 보고 있다면, 여기 있는 튜토리얼과 샘플 코드 섹션에 소스파일들이 있다.)

In its manifest file, the Note Pad application declares three activities, each with at least one intent filter. It also declares a content provider that manages the note data. Here is the manifest file in its entirety:

그것의 매니페스트 파일에서, 노트 패드 애플리케이션을 세 개의 액티비티를 선언하고 있으며, 그것들 각각은 적어도 하나의 인텐트 필터를 가지고 있다. 노트 데이트를 관리하는 컨텐트 프로바이더 또한 선언되어 있다. 여기에 전체 그대로의 매니페스트 파일이 있다.

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

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

        <activity android:name="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 android:name="NoteEditor"
                  android:theme="@android:style/Theme.Light"
                  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" />
                <action android:name="com.android.notepad.action.EDIT_NOTE" />
                <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 android:name="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>

The first activity, NotesList, is distinguished from the other activities by the fact that it operates on a directory of notes (the note list) rather than on a single note. It would generally serve as the initial user interface into the application. It can do three things as described by its three intent filters:

첫번째 액티비티인 NotesList는 단일 노트가 아닌 노트 디렉토리(노트 목록)를 조작한다는 점에서 다른 액티비티와 구분된다. 그것은 일반적으로 애플리케이션에 대한 초기 사용자 인터페이스를 제공할 것이다. 그것의 세 개의 인텐트 필터에 의해 설명되고 있듯이 세 가지 것을 할 수 있다.

  1. <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    This filter declares the main entry point into the Note Pad application. The standard MAIN action is an entry point that does not require any other information in the Intent (no data specification, for example), and the LAUNCHER category says that this entry point should be listed in the application launcher.

  2. <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>

    This filter declares the things that the activity can do on a directory of notes. It can allow the user to view or edit the directory (via the VIEW and EDIT actions), or to pick a particular note from the directory (via the PICK action).

    The mimeType attribute of the <data> element specifies the kind of data that these actions operate on. It indicates that the activity can get a Cursor over zero or more items (vnd.android.cursor.dir) from a content provider that holds Note Pad data (vnd.google.note). The Intent object that launches the activity would include a content: URI specifying the exact data of this type that the activity should open.

    Note also the DEFAULT category supplied in this filter. It's there because the Context.startActivity() and Activity.startActivityForResult() methods treat all intents as if they contained the DEFAULT category with just two exceptions:

    • Intents that explicitly name the target activity
    • Intents consisting of the MAIN action and LAUNCHER category

    Therefore, the DEFAULT category is required for all filters except for those with the MAIN action and LAUNCHER category. (Intent filters are not consulted for explicit intents.)

  3. <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>

    This filter describes the activity's ability to return a note selected by the user without requiring any specification of the directory the user should choose from. The GET_CONTENT action is similar to the PICK action. In both cases, the activity returns the URI for a note selected by the user. (In each case, it's returned to the activity that called startActivityForResult() to start the NoteList activity.) Here, however, the caller specifies the type of data desired instead of the directory of data the user will be picking from.

    The data type, vnd.android.cursor.item/vnd.google.note, indicates the type of data the activity can return a URI for a single note. From the returned URI, the caller can get a Cursor for exactly one item (vnd.android.cursor.item) from the content provider that holds Note Pad data (vnd.google.note).

    In other words, for the PICK action in the previous filter, the data type indicates the type of data the activity could display to the user. For the GET_CONTENT filter, it indicates the type of data the activity can return to the caller.

  1. <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    이 필터는 노트 패드 애플리케이션에 대한 메인main 시작 점을 선언한다. 표준 MAIN 액션은 인텐트 내에 어떤 다른 정보도 요구하지 않으며(예를들어, 데이터 명세가 없음), LAUNCHER 카테고리는 이 시작점이 애플리케이션 런처안에 나열되어야 한다는 것을 말한다.

  2. <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>

    이 필터는 노트 디렉토리에서 액티비티가 할 수 있는 것들을 선언한다. 그것은 사용자에게 (VIEW와 EDIT 액션을 통해) 디렉토리를 보거나 수정할 수 있게 하며, 또한 (PICK 액션을 통해) 그 디렉토리에서 특정 노트를 가져올 수 있게 한다.

    <data> 엘리먼트의 mimeType 애트리뷰트는 이러한 액션들이 처리하는 데이터의 종류를 지정한다. 그것은 해당 액티비티가 노트 패드 데이터(vnd.google.note)를 보유하고 있는 컨텐트 프로바이더로부터 0개 또는 그 이상의 아이템들(vnd.android.cursor.dir)을 담고있는 커서를 얻을 수 있다는 것을 가리킨다. 그 액티비티를 런치하는 인텐트 오브젝트는 그 액티비트가 오픈해야하는 정확한 데이터 타입을 명시하는 content: URI를 포함할 것이다.

    이 인텐트 필터에 DEFAULT 카테고리가 제공되었다는 것에 주의하라. 그것이 있는 것은, Context.startActivity()와 Activity.startActivityFor Result() 메쏘드가 마치 DAFAULT 카테고리를 포함하고 있는 것처럼 아래의 두개의 예외사항을 보유한 채로, 모든 인텐트를 취급하기 때문이다.

    • 타겟 액티비트를 명시적으로 지칭하는 인텐트
    • MAIN 액션과 LAUNCHER 카테고리로 구성된 인텐트

    그러므로, DEFAULT 카테고리는 모든 필터에서 필수이다 - MAIN 액션과 LAUNCHER 카테고리를 가진 것은 제외함. (인텐트 필터는 명시적 인텐트를 염두에 둔 것이 아니다.)

  3. <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>

    이 필터는 사용자가 선택해야하는 디렉토리에 대한 어떤 명세도 요구하지 않고 사용자에 의해 선택된 노트를 반환하는 액티비티의 능력을 설명한다. GET_CONTENT 액션은 PICK 액션과 유사하다. 두 경우 모두, 액티비티는 사용자에 의해 선택된 노트에 대한 URI를 반환한다.(각각의 경우에, NoteList 액티비티를 시작시키기 위해 startActivityForResult()를 호출했던 액티비티에 그것이 반환된다.) 하지만, 여기에서 호출자는 사용자가 가져오게 될 데이터 디렉토리 대신에 원하는 데이터 타입을 지정하고 있다.

    데이터 타입 vnd.android.cursor.item/vnd.google.note는 하나의 노트에 대한 URI로, 액티비티가 반환할 수 있는 데이터 타입을 가리킨다. 반환된 URI로부터, 호출자는 노트 패드 데이터(vnd.google.note)를 보유하고 있는 컨텐트 프로바이더로부터 정확하게 하나의 아이템(vnd.android.cursor.item)에 대한 커서를 얻을 수 있다.

    바꿔 말하면, 앞의 필터에 있던 PICK 액션에 대한 데이터 타입은 사용자에게 표시될 수 있는 액티비티의 데이터 타입을 가리킨다. GET_CONTENT 필터의 경우에, 그것은 호출자에게 반환될 수 있는 액티비티의 데이터 타입을 가리킨다.

Given these capabilities, the following intents will resolve to the NotesList activity:

이와 같이 주어진 능력들은, 다음과 같은 인텐트들을 NoteList 액티비티에 확정할 것이다.

action: android.intent.action.MAIN
Launches the activity with no data specified.
action: android.intent.action.MAIN
category: android.intent.category.LAUNCHER
Launches the activity with no data selected specified. This is the actual intent used by the Launcher to populate its top-level list. All activities with filters that match this action and category are added to the list.
action: android.intent.action.VIEW
data: content://com.google.provider.NotePad/notes
Asks the activity to display a list of all the notes under content://com.google.provider.NotePad/notes. The user can then browse through the list and get information about the items in it.
action: android.intent.action.PICK
data: content://com.google.provider.NotePad/notes
Asks the activity to display a list of the notes under content://com.google.provider.NotePad/notes. The user can then pick a note from the list, and the activity will return the URI for that item back to the activity that started the NoteList activity.
action: android.intent.action.GET_CONTENT
data type: vnd.android.cursor.item/vnd.google.note
Asks the activity to supply a single item of Note Pad data.
action: android.intent.action.MAIN
지정된 어떤 데이터도 없이 액티비티를 런치한다.
action: android.intent.action.MAIN category: android.intent.category.LAUNCHER
선택되어 지정된 어떤 데이터도 없이 액티비티를 런치한다. 이것은 런처가 그것의 최상위 목록을 구성하기 위해 사용되는 실제 인텐트이다. 이 액션과 카테고리와 일치되는 필터를 가진 모든 액티비티들은 그 목록에 추가된다.
action: android.intent.action.VIEW data: content://com.google.provider.NotePad/notes
content://com.google.provider.NotePad/notes 아래의 모든 노트 목록을 표시할 액티비티를 요청한다. 그런 다음, 사용자는 그 목록을 열람할 수 있고, 그곳에서 아이템에 대한 정보를 얻을 수 있다.
action: android.intent.action.PICK data: content://com.google.provider.NotePad/notes
content://com.google.provider.NotePad/notes 아래의 노트 목록을 표시할 액티비티를 요청한다. 그런 다음에, 사용자는 그 목록에서 노트를 가져올 수 있고, 그 액티비티는 NoteList 액티비티를 시작했던 액티비티에게 그 아이템에 대한 URI를 반환할 것이다.
action: android.intent.action.GET_CONTENT data type: vnd.android.cursor.item/vnd.google.note
하나의 노트 패드 데이터 아이템을 제공하는 액티비티를 요청한다.

The second activity, NoteEditor, shows users a single note entry and allows them to edit it. It can do two things as described by its two intent filters:

두번 째 액티비티인 NoteEditor는 사용자에게 하나의 노트 입력란을 보여주며, 그것을 편집하는 것을 가능하게 한다. 그것은 두개의 인텐트 필터에 의해 설명되듯이 두 가지 것을 할 수 있다.

  1. <intent-filter android:label="@string/resolve_edit">
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.EDIT" />
        <action android:name="com.android.notepad.action.EDIT_NOTE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    </intent-filter>

    The first, primary, purpose of this activity is to enable the user to interact with a single note &mdash to either VIEW the note or EDIT it. (The EDIT_NOTE category is a synonym for EDIT.) The intent would contain the URI for data matching the MIME type vnd.android.cursor.item/vnd.google.note that is, the URI for a single, specific note. It would typically be a URI that was returned by the PICK or GET_CONTENT actions of the NoteList activity.

    As before, this filter lists the DEFAULT category so that the activity can be launched by intents that don't explicitly specify the NoteEditor class.

  2. <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>

    The secondary purpose of this activity is to enable the user to create a new note, which it will INSERT into an existing directory of notes. The intent would contain the URI for data matching the MIME type vnd.android.cursor.dir/vnd.google.note that is, the URI for the directory where the note should be placed.

  1. <intent-filter android:label="@string/resolve_edit">
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.EDIT" />
        <action android:name="com.android.notepad.action.EDIT_NOTE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    </intent-filter>

    이 액티비트의 첫번째 기본적인 목적은, 사용자가 노트를 VIEW 하거나 그것을 EDIT 하도록 하나의 노트와 상호작용하는 것을 가능하게 하는 것이다. (EDIT_NOTE 카테고리는 EDIT와 동의어이다.) 그 인텐트는 MIME 타입 vnd.android.cursor.item/vnd.google.note와 일치하는 데이터에 대한 URI, 즉 하나의 특정 노트에 대한 URI를 포함할 것이다. 그것은 전형적으로 NoteList 액티비티의 PICK 또는 GET_CONTENT 액션에 의해 반환되는 URI가 될 것이다.

    앞에서 처럼, 이 필터는 액티비티가 NoteEditor 클래스를 명시적으로 지정하지 않은 인텐트에 의해서 런치될 수 있도록 DEFAULT 카테고리를 포함한다.

  2. <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>

    이 액티비티의 두번째 목적은 사용자가 신규 노트를 생성하는 것을 가능하게 하는 것이다. 그 노트는 이미 존재하는 노트 디렉토리에 INSERT 될 것이다. 그 인텐트는 MIME 타입 vnd.android.cursor.dir/vnd.google.note와 일치하는 데이터에 대한 URI, 즉 노트가 놓여져야 하는 디렉토리게 대한 URI를 포함할 것이다.

Given these capabilities, the following intents will resolve to the NoteEditor activity:

이와 같이 주어진 능력들은, 다음과 같은 인텐트들을 NoteEditor 액티비티에 확정할 것이다.

action: android.intent.action.VIEW
data: content://com.google.provider.NotePad/notes/ID
Asks the activity to display the content of the note identified by ID. (For details on how content: URIs specify individual members of a group, see Content Providers.)
action: android.intent.action.EDIT
data: content://com.google.provider.NotePad/notes/ID
Asks the activity to display the content of the note identified by ID, and to let the user edit it. If the user saves the changes, the activity updates the data for the note in the content provider.
action: android.intent.action.INSERT
data: content://com.google.provider.NotePad/notes
Asks the activity to create a new, empty note in the notes list at content://com.google.provider.NotePad/notes and allow the user to edit it. If the user saves the note, its URI is returned to the caller.
action: android.intent.action.VIEW data: content://com.google.provider.NotePad/notes/ID
ID로 식별되는 노트 컨텐트를 보여줄 액티비티를 요청한다. (content: URI가 어떤 그룹의 개별 구성물을 지정하는 상세한 방법에 대해서는, Content Providers를 보라.)
action: android.intent.action.EDIT data: content://com.google.provider.NotePad/notes/ID
ID로 식별되는 노트 컨텐트를 보여주고 사용자가 그것을 편집할 수 있게 할 액티비티를 요청한다, 만약 사용자가 변경분을 저장하면, 액티비티는 컨텐트 프로바이더에 있는 노트에 대한 데이터를 갱신한다.
action: android.intent.action.INSERT data: content://com.google.provider.NotePad/notes
content://com.google.provider.NotePad/notes에 있는 노트 목록에 신규로 빈 노트를 생성하고 사용자가 그것을 편집할 수 있게 할 액티비티를 요청하다. 만약 사용자가 노트를 저장하면, 그것의 URI가 호출자에게 반환된다.

The last activity, TitleEditor, enables the user to edit the title of a note. This could be implemented by directly invoking the activity (by explicitly setting its component name in the Intent), without using an intent filter. But here we take the opportunity to show how to publish alternative operations on existing data:

마지막 액티비티인 TitleEditor는 사용자가 노트의 제목을 편집하는 것을 가능하게 한다. 이것은 (명시적으로 인텐트에 그 컴포넌트 이름을 셋팅함으로써) 인텐트 필터를 사용하지 않고 직접적으로 그 액티비티를 호출함으로써 구현될 수 있다. 그러나 우리는 여기에서 존재하는 데이터에 택일적 오퍼레이션을 배포하는 방법을 보여주는 기회를 갖는다.

<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>

The single intent filter for this activity uses a custom action called "com.android.notepad.action.EDIT_TITLE". It must be invoked on a specific note (data type vnd.android.cursor.item/vnd.google.note), like the previous VIEW and EDIT actions. However, here the activity displays the title contained in the note data, not the content of the note itself.

이 액티비티에 대한 하나의 인텐트 필터는 “com.android.notepad.action.EDIT_TITLE”라 불리는 커스텀 액션을 사용한다. 그것은 이전의 VIEW와 EDIT 액션과 같이 특정 노트(데이터 타입 vnd.android.cursor.item/vnd.google.note)에 호출되어야 한다. 하지만, 여기에서 그 액티비티는 노트 컨텐트 자체가 아닌, 그 노트 데이터에 포함된 제목을 보여준다.

In addition to supporting the usual DEFAULT category, the title editor also supports two other standard categories: ALTERNATIVE and SELECTED_ALTERNATIVE. These categories identify activities that can be presented to users in a menu of options (much as the LAUNCHER category identifies activities that should be presented to user in the application launcher). Note that the filter also supplies an explicit label (via android:label="@string/resolve_title") to better control what users see when presented with this activity as an alternative action to the data they are currently viewing. (For more information on these categories and building options menus, see the PackageManager.queryIntentActivityOptions() and Menu.addIntentOptions() methods.)

통상적인 DEFAULT 카테고리를 지원하는 것에 추가해서, 제목 편집기는 또한 두개의 다른 표준 카테고리인 ALTERNATIVE와 SELECTED_ALTERNATIVE를 지원한다. 이 카테고리들은 (LAUNCHER 카테고리가 애플리케이션 런처에서 사용자에게 보여져야하는 액티비티를 구분하는 것처럼) 옵션 메뉴에서 사용자에게 보여질 수 있는 액티비티를 구분한다. 이 필터는 또한 (android:label=”@string/resolve_title” 를 통해) 명시적인 라벨을 제공하고 있음에 주의하라. 이것은 사용자가 현재 보고 있는 데이터에 대한 택일적 액션으로써 이 액비티비를 표시될 때 사용자가 보는 것을 더 좋게 보도록 하기 위한 것이다. (이 카테고리에 대한 더 자세한 정보와 옵션 메뉴 구성은, PackageManager.queryIntentActivityOptions()와 Menu.addIntentOptions() 메쏘드를 보라.)

Given these capabilities, the following intent will resolve to the TitleEditor activity:

이와 같이 주어진 능력들은, 다음과 같은 인텐트들을 TitleEditor 액티비티에 확정할 것이다.

action: com.android.notepad.action.EDIT_TITLE
data: content://com.google.provider.NotePad/notes/ID
Asks the activity to display the title associated with note ID, and allow the user to edit the title.
action: com.android.notepad.action.EDIT_TITLE data: content://com.google.provider.NotePad/notes/ID
노트 ID와 결합된 제목을 보여주고, 사용자에게 제목을 편집할 수 있게 하는 액티비티를 요청한다.
↑ Go to top