2012년 5월 7일 월요일

Intents and Intent Filters 02

Intent Resolution

  • 인텐트는 두가지 그룹으로 나뉜다.
  • Explicit intents 컴퍼넌트 이름으로 타겟 컴퍼넌트를 지정한다. 외연적 인텐트은 하위 서비스나 자매 액티비티 실행 같은 어플 내부 메세지로 사용된다.
    Implicit intents 컴퍼넌트 이름을 지정하지 않고 다른 어플의 컴퍼넌트를 활성화시키는 데 사용된다.
  • Implicit Intents는 인텐트를 처리할 최적의 컴퍼넌트를 찾기 위해 인텐트 개체의 내용을 Intent filter와 비교한다.
  • 인텐트 필터는 컴퍼넌트의 능력을 알리고 그것이 다룰 수 있는 인텐트를 제한한다.
  • 인텐트 필터를 갖춘 컴퍼넌트는 explicit/implicit intents를 둘 다 처리할 수 있지만, 그렇지 않을 경우 explicit intents만 수신할 수 있다.
  • 인텐트는 action, data(uri/data type), category), category등의 세가지 측면에서 인텐트 필터로 테스트된다.

Intent filters

  • 시스템에게 어떤 implicit intents를 다룰 수 있는지 알리기 위해 액티비티, 서비스, 브로드캐스트 리시버는 하나 이상의 인텐트 필터를 가질 수 있다.
  • 필터는 컴포넌트가 수신하고자 하는 일련의 인텐트 집합을 기술한다.
Action test
  • manifest 파일에 의 하위 엘러먼트 로 액션들을 나열한다.
  • <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>
Category test
  • <intent-filter> 엘러먼트는 action 엘러먼트와 같이 category를 하위 엘러먼트로 가진다.
  • <intent-filter . . . >
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        . . .
    </intent-filter>
  • 액션과 카테고리를 위한 상수 대신 문자열이 사용된다. CATEGORY_BROWSABLE에는 android.intent.category.BROWSABLE, ACTION_EDIT에는 android.intent.action.EDIT를 사용한다.
Data test
  • 액션과 카테고리처럼 데이타 역시 인텐트의 하위 엘러먼트로 포함된다.
  • <intent-filter . . . >
        <data android:mimeType="video/mpeg" android:scheme="http" . . . /> 
        <data android:mimeType="audio/mpeg" android:scheme="http" . . . />
        . . .
    </intent-filter>
  • 데이터 엘러먼트는 URI와 데이터 타입(MIME 미디어 타입)을 지정한다.
  • URI는 scheme, host, port 부분들로 이루어 진다.
  • scheme://host:port/path (ex. content://com.example.project:200/folder/subfolder/etc)
  • 데이터 패스 규칙
  • Intent object filter result
    URI data type URI data type
    xx xxpass
    ox oxpass
    xo xopass
    oo oopass
  • 인텐트가 하나 이상의 액티비티 또는 서비스의 필터를 통과하면 사용자는 어떤 컴퍼넌트를 활성화할 것인지 질의받는다. 대상이 존재하지 않는다면 예외가 발생한다.
Common cases
  • 컴퍼넌트는 파일 또는 콘텐트 프로바이더에 로컬 데이터를 얻는 경우 content:/file: scheme를 지정함이 없이 데이터 타입만을 나열한다.
  • 예를 들어 콘텐트 프로바이더으로부터 이미지 데이터를 얻는 컴퍼넌트를 다음과 같이 지정할 수 있다.
  • <data android:mimeType="image/*" />
  • 일반적인 경우 스킴과 데이터 타입을 다음과 같이 지정하여 컴퍼넌트가 네트워크에서 비디오 데이터를 구할 수 있게 한다.
  • <data android:scheme="http" android:type="video/*" />
  • 어플을 초기화하는 액티비티들은 "android.intent.action.MAIN" action를 포함하는 필터들을 가진다. 그들이 어플 론처로 나타난다면 "android.intent.category.LAUNCHER" category 역시 지정한다.
  • <intent-filter . . . >
        <action android:name="code android.intent.action.MAIN" />
        <category android:name="code android.intent.category.LAUNCHER" />
    </intent-filter>
Using intent matching
  • 인텐트는 인텐트 필터에 대칭되어 비교될 뿐만 아니라 장치내 컴퍼넌트들에 대한 것들 탐색하게 한다.
  • PackageManager는 특정 인텐트를 수용할 수 잇는 모든 컴퍼넌트를 리턴하는 query..() 메서들과 인텐트에 반응하는 최적의 컴퍼넌트를 결정하는 resolve...() 메서드들을 가진다.
  • queryIntentActivities() 인텐트에 대해 인수로 받아 그것에 대해 수행할 수 있는 모든 액티비티 리스트를 반환
    queryIntentServices()
    queryBroadcastReceivers()

댓글 없음:

댓글 쓰기