我正在尝试定义一个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" />
没有运气。只有DEFAULT。删除元素将导致它被触发。
可以这样做吗? Android文档仅显示元素中使用MIME类型的示例.....
任何帮助表示感谢。
答案 0 :(得分: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>
答案 1 :(得分:3)
此格式适合我
<data android:scheme="http" android:host="www.domain.com" android:pathPattern=".*" />
答案 2 :(得分:-1)
我做过类似的事情,但我认为你不能使用uri。您需要编写MIME ndef消息,并使用intent过滤器将自定义mime类型(如x-myapp / mydemo)分配给您的活动。然后,您可以读取任何内容,例如URL,并触发Web浏览器。