Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

Any help appreciated.

like image 200
Andrew Mackenzie Avatar asked Apr 02 '26 01:04

Andrew Mackenzie


1 Answers

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>
like image 181
Andrew Mackenzie Avatar answered Apr 03 '26 18:04

Andrew Mackenzie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!