android - NFC tag is not discovered for ACTION_NDEF_DISCOVERED action even if it contains Ndef data -


i trying read 2 different nfc tags samsung s5. both tags contain ndef message, first tag contains mime type record first record , second tag contains alternative carrier record (tnf = tnf_well_known, type = rtd_alternative_carrier) first record.

when read tags through foreground dispatch using action_tech_discovered intent. first tag, tech-list lists nfca, mifareclassic, , ndef. second tag, lists nfca , ndef.

when try read tag using action_ndef_discovered intent using datatype "*/*" , first tag discovered fine, second tag not discovered @ all.

the problem here how ndef_discovered intent filter works. ndef_discovered can either watch datatype (i.e. mime type) or uri. in cases, matching applied first record in ndef message of discovered tag.

with datatype matching, can detect

  • a mime type record contains given mime media type or
  • a text rtd record (tnf_well_known + rtd_text) maps mime type "text/plain".

with uri matching, can detect

  • a uri rtd record (tnf_well_known + rtd_uri),
  • a uri rtd record encapsulated inside smart poster rtd record,
  • a record uri based type (tnf_absolute_uri), or
  • an nfc forum external type record (tnf_external).

both matching types mutually exclusive, can either match datatype or uri in 1 intent filter.

in case of second tag, type of first record (tnf_well_known + rtd_alternative_carrier) not supported ndef intent dispatch system. hence, cannot use ndef_discovered intent filter in combination tag.

examples

matching datatype:

  • in manifest:

    <intent-filter>     <action android:name="android.nfc.action.ndef_discovered"/>     <category android:name="android.intent.category.default"/>     <data android:mimetype="some/mimetype" /> </intent-filter> 
  • in code:

    intentfilter ndef = new intentfilter(nfcadapter.action_ndef_discovered); ndef.adddatatype("some/mimetype"); 

matching url:

  • in manifest:

    <intent-filter>     <action android:name="android.nfc.action.ndef_discovered"/>     <category android:name="android.intent.category.default"/>     <data android:scheme="http"           android:host="somehost.example.com"           android:pathprefix="/somepath" /> </intent-filter> 
  • in code:

    intentfilter ndef = new intentfilter(nfcadapter.action_ndef_discovered); ndef.adddatascheme("http"); ndef.adddataauthority("somehost.example.com", null); ndef.adddatapath("/somepath", patternmatcher.pattern_prefix); 

matching nfc forum external type:

  • in manifest:

    <intent-filter>     <action android:name="android.nfc.action.ndef_discovered"/>     <category android:name="android.intent.category.default"/>     <data android:scheme="vnd.android.nfc"           android:host="ext"           android:pathprefix="/com.example:sometype" /> </intent-filter> 
  • in code:

    intentfilter ndef = new intentfilter(nfcadapter.action_ndef_discovered); ndef.adddatascheme("vnd.android.nfc"); ndef.adddataauthority("ext", null); ndef.adddatapath("/com.example:sometype", patternmatcher.pattern_prefix); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -