Andrew Mackenzie
Andrew Mackenzie

Reputation: 5745

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.

Upvotes: 3

Views: 3412

Answers (3)

Andrew Mackenzie
Andrew Mackenzie

Reputation: 5745

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>

Upvotes: 5

Robert James Whelan
Robert James Whelan

Reputation: 49

This format works for me

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

Upvotes: 4

Sven Haiges
Sven Haiges

Reputation: 2636

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.

Upvotes: -1

Related Questions