Question

I am trying to store a very small (1K) html file on a NFC tag. When read by a phone, it should trigger the Browser to open it.

Sadly I have those constrains :

  • HTML file (1kb) Stored on the tag. Not just a url. (The user don't have internet)
  • Not text/plain, it should be text/html.
  • It should be opened by the default browser, not a custom tailored app.

I created the tag this way :

      Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
      NdefRecord record = NdefRecord.createMime( "text/html", "Hello world in <b>HTML</b> !");
      NdefMessage message = new NdefMessage(new NdefRecord[] { record });
      if (writeTag(message, detectedTag)) {
          Toast.makeText(this, "Success: Wrote placeid to nfc tag", Toast.LENGTH_LONG)
              .show();
      } 

But for some reason, when the tag is read, the default browser is not opened. Even though the browser do have the right intent filter:

        <!-- For these schemes where any of these particular MIME types have been supplied, we are a good candidate. -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:mimeType="text/html"/>
            <data android:mimeType="text/plain"/>
            <data android:mimeType="application/xhtml+xml"/>
            <data android:mimeType="application/vnd.wap.xhtml+xml"/>
        </intent-filter>

Did I do something wrong ?

Thanks !

Was it helpful?

Solution 2

Hmm..

Apparently it is not possible, the manifest specifies this :

https://android.googlesource.com/platform/packages/apps/Browser/+/ics-mr0/AndroidManifest.xml

    <!-- Accept inbound NFC URLs at a low priority -->
    <intent-filter android:priority="-101">
        <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="http" />
        <data android:scheme="https" />
    </intent-filter>

That's so restrictive. No wonder why QR codes win over NFC.

Please, vote for my feature request if you think so too !

https://code.google.com/p/android/issues/detail?id=68668

OTHER TIPS

You need to create the record as a URI. Such as:

NdefRecord rtdUriRecord1 = NdefRecord.createUri("http://example.com");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top