<uri-relative-filter-group>

문법:
<uri-relative-filter-group android:allow=["true" | "false"]>
  <data ... />
  ...
</uri-relative-filter-group>
포함된 위치:
<intent-filter>
포함 가능한 요소:
<data>
설명:
URI 쿼리 매개변수와 URI 프래그먼트를 포함할 수 있는 정확한 Intent 일치 규칙을 만듭니다. 규칙은 android:allow 속성에 따라 포함 (허용) 규칙 또는 제외 (차단) 규칙일 수 있습니다. 일치 규칙은 포함된 <data> 요소의 path*, fragment*, query* 속성으로 지정됩니다.

일치

URI와 일치하려면 URI 상대 필터 그룹의 각 부분이 URI의 일부와 일치해야 합니다. URI 상대 필터 그룹에 지정되지 않은 URI 부분이 있을 수 있습니다. 예를 들면 다음과 같습니다.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="true">
    <data android:query="param1=value1" />
    <data android:query="param2=value2" />
  </uri-relative-filter-group>
  ...
</intent-filter>

URI 상대 필터 그룹에 의해 지정된 모든 항목이 있으므로 필터가 https://project.example.com/any/path/here?param1=value1&param2=value2&param3=value3와 일치합니다. 쿼리 매개변수의 순서는 중요하지 않으므로 필터는 https://project.example.com/any/path/here?param2=value2&param1=value1와도 일치합니다. 하지만 필터는 https://project.example.com/any/path/here?param1=value1와 일치하지 않습니다. https://project.example.com/any/path/here?param1=value1에는 param2=value2이 누락되어 있습니다.

OR 및 AND

<uri-relative-filter-group> 외부에 있는 <data> 태그는 OR로 연결되고 <uri-relative-filter-group> 내부에 있는 <data> 태그는 AND로 연결됩니다.

다음 예를 참고하세요.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <data android:pathPrefix="/prefix" />
  <data android:pathSuffix="suffix" />
  ...
</intent-filter>

필터는 /prefix로 시작하거나 suffix로 끝나는 경로와 일치합니다.

반면 다음 예는 /prefix로 시작하고 suffix로 끝나는 경로와 일치합니다.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group>
    <data android:pathPrefix="/prefix" />
    <data android:pathSuffix="suffix" />
  </uri-relative-filter-group>
  ...
</intent-filter>

따라서 동일한 <uri-relative-filter-group>의 여러 path 속성은 아무것과도 일치하지 않습니다.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group>
    <data android:path="/path1" />
    <data android:path="/path2" />
  </uri-relative-filter-group>
  ...
</intent-filter>

선언 순서

다음 예를 참고하세요.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group>
    <data android:fragment="fragment" />
  </uri-relative-filter-group>
  <uri-relative-filter-group android:allow="false">
    <data android:fragmentPrefix="fragment" />
  </uri-relative-filter-group>
  ...
</intent-filter>

제외 규칙이 평가되기 전에 일치 항목이 발견되므로 필터가 #fragment 프래그먼트와 일치하지만 #fragment123과 같은 프래그먼트는 일치하지 않습니다.

동위 요소 태그

<uri-relative-filter-group> 태그는 형제 <data> 태그(즉, <uri-relative-filter-group> 외부에 있지만 동일한 <intent-filter> 내부에 있는 <data> 태그)와 함께 작동합니다. <uri-relative-filter-group> 태그는 URI 속성이 <intent-filter> 수준에서 상호 종속적이므로 제대로 작동하려면 형제 <data> 태그가 있어야 합니다.

  • 인텐트 필터에 scheme이 지정되지 않으면 다른 모든 URI 속성이 무시됩니다.
  • 필터에 host이 지정되지 않으면 port 속성과 모든 path* 속성이 무시됩니다.

<intent-filter>의 <data> 하위 요소는 <uri-relative-filter-group> 태그보다 먼저 평가됩니다. 그런 다음 <uri-relative-filter-group> 태그가 순서대로 평가됩니다. 예를 들면 다음과 같습니다.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="false">
    <data android:path="/path" />
    <data android:query="query" />
  </uri-relative-filter-group>
  <data android:path="/path" />
  ...
</intent-filter>

필터는 <uri-relative-filter-group> 제외 규칙 외부에 있는 <data android:path="/path" />와 일치하므로 https://project.example.com/path?query를 허용합니다.

일반적인 사용 사례

쿼리 매개변수의 존재 여부 또는 값에 따라 Intent과 일치시키려는 URI https://project.example.com/path가 있다고 가정해 보겠습니다. https://project.example.com/path와 일치하고 https://project.example.com/path?query를 차단하는 인텐트 필터를 만들려면 다음과 같이 시도해 보세요.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="true">
    <data android:path="/path" />
  </uri-relative-filter-group>
  ...
</intent-filter>

실제로 작동하지 않습니다. https://project.example.com/path?query URI는 /path 경로와 일치하며 <uri-relative-filter-group> 태그는 일치할 때 추가 부분을 허용합니다.

다음과 같이 인텐트 필터를 수정합니다.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="false">
    <data android:path="/path" />
    <data android:queryAdvancedPattern=".+" />
  </uri-relative-filter-group>
  <uri-relative-filter-group android:allow="true">
    <data android:path="/path" />
  </uri-relative-filter-group>
  ...
</intent-filter>

이 필터는 비어 있지 않은 쿼리 매개변수를 금지하는 차단 규칙이 먼저 평가되기 때문에 작동합니다.

코드를 간소화하려면 동작을 전환하여 쿼리 매개변수를 허용하고 쿼리 매개변수가 없는 URI를 차단하세요.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="true">
    <data android:path="/path" />
    <data android:queryAdvancedPattern=".+" />
  </uri-relative-filter-group>
  ...
</intent-filter>

URI 인코딩된 문자

URI로 인코딩된 문자가 포함된 URI를 일치시키려면 필터에 인코딩되지 않은 원시 문자를 작성합니다. 예를 들면 다음과 같습니다.

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="true">
    <data android:query="param=value!" />
  </uri-relative-filter-group>
  ...
</intent-filter>

필터는 ?param=value! 및 ?param=value%21와 일치합니다.

하지만 다음과 같이 필터에 인코딩된 문자를 작성하면

<intent-filter...>
  <data android:scheme="https" android:host="project.example.com" />
  <uri-relative-filter-group android:allow="true">
    <data android:query="param=value%21" />
  </uri-relative-filter-group>
  ...
</intent-filter>

필터가 ?param=value! 또는 ?param=value%21와 일치하지 않습니다.

요소 수

<intent-filter> 내부에 <uri-relative-filter-group> 요소를 원하는 수만큼 배치할 수 있습니다.

추가 리소스

인텐트 객체와 필터의 일치 방식에 적용되는 규칙을 포함하여 인텐트 필터의 작동 방식에 관한 자세한 내용은 인텐트 및 인텐트 필터와 인텐트 필터를 참고하세요.

<uri-relative-filter-group>에 관한 자세한 내용은 UriRelativeFilterGroup 및 UriRelativeFilter를 참고하세요.

속성:
android:allow
이 URI 상대 필터 그룹이 제외 (차단) 규칙이 아닌 포함 (허용) 규칙인지 여부입니다. 기본값은 "true"입니다.
값 설명
"true"(기본) URI 상대 필터 그룹이 일치하면 인텐트 필터가 일치합니다.
"false" URI 상대 필터 그룹이 일치하면 인텐트 필터가 일치하지 않습니다.
도입 수준:
API 수준 35
참고 항목:
<intent-filter>
<data>