3

我正在尝试定义一个 Intent 过滤器,它只会在我收到包含特定网站 URI 的 NDEF 消息时触发。

我的定义是这样的:

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:host="ta.bcntouch.com" />
        </intent-filter>

但它不会那样触发。我也试过:

            <data android:scheme="http"android:host="ta.bcntouch.com" />

没有运气。也只是默认值。删除元素将导致它触发。

这可以做到吗?Android 文档仅显示了在元素中使用 MIME 类型的示例.....

任何帮助表示赞赏。

4

3 回答 3

5

这是我最终使用的过滤器,用于捕获一些特定的已知 URL 组合。

主机字段开头的“*”允许我在使用子域中的测试服务器进行测试时使用相同的过滤器,或者使用相同的名称格式。

第二个(查看)从网页、电子邮件等中捕获相同的 URL 格式......:

        <intent-filter>
          <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
          <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/p/.*" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/l/.*" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/a.*" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/t.*" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/p/.*" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/l/.*" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/a.*" />
            <data android:scheme="http"
                  android:host="*ta.bcntouch.com" 
                  android:pathPattern="/t/.*" />
        </intent-filter>
于 2012-10-18T07:51:30.520 回答
4

这种格式适合我

<data android:scheme="http" android:host="www.domain.com" android:pathPattern=".*" />
于 2012-02-03T19:34:06.960 回答
-1

我做过类似的事情,但我认为你不能使用 uri。您需要编写 MIME ndef 消息并使用意图过滤器将自定义 mime 类型(如 x-myapp/mydemo)分配给您的活动。然后,您可以阅读任何内容,例如 URL,并触发 Web 浏览器。

于 2011-05-06T12:27:53.573 回答