开发者

Android NDEF intent-filter with data for http scheme and host

开发者 https://www.devze.com 2023-02-28 09:34 出处:网络
I am trying to define an Intent filter that will only trigger when I receive NDEF messages that contain the URI of a particular web site.

I am trying to define an Intent filter that will only trigger when I receive NDEF messages that contain the URI of a particular web site.

I have it defined like this:

        <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>

But it won't trigger like that. I have also tried:

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

With no luck. Also with just DEFAULT. Removing the element will cause it to 开发者_C百科trigger.

Can this be done? The Android documentation only shows examples using MIME type in the element.....

Any help appreciated.


Here is the filters I finally used, to capture a number of specific known URL combinations.

The '*' at the start of the host field allows me to use the same filter when testing with test servers that are in a sub-domain, or follow the same format for name.

The second (View) one captures the same URL formats from web-pages, emails, etc...:

        <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>


This format works for me

<data android:scheme="http" android:host="www.domain.com" android:pathPattern=".*" />


I have done something similar, but I think you cannot use the uri. You need to write a MIME ndef message and assign the custom mime type like x-myapp/mydemo to your activity using the intent filter. you can then read any content, like a URL for example, and trigger a web browser for example.

0

精彩评论

暂无评论...
验证码 换一张
取 消