溫馨提示×

IntentFilter如何配置數(shù)據(jù)類型

小樊
87
2024-07-03 12:02:12
欄目: 編程語言

IntentFilter可以通過配置元素來指定數(shù)據(jù)類型。具體配置如下:

  1. 指定數(shù)據(jù)類型:可以通過設(shè)置元素的android:mimeType屬性來指定數(shù)據(jù)類型。例如,指定數(shù)據(jù)類型為text/plain:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>
  1. 指定URI格式:可以通過設(shè)置元素的android:scheme、android:host、android:port、android:path等屬性來指定URI格式。例如,指定URI格式為http協(xié)議的網(wǎng)址:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:scheme="http"
        android:host="www.example.com"
        android:pathPrefix="/path"
    />
</intent-filter>

通過配置元素,可以精確地指定IntentFilter的數(shù)據(jù)類型,從而確保只有特定類型的數(shù)據(jù)可以觸發(fā)該IntentFilter。

0