android - How to properly read nfc tag -


I am correctly setting up an NFC environment:

  • Technology Filter

      & lt; Resource xmlns: xliff = "vase: oasis: name: tc: xliff: document: 1.2" & gt; & Lt; Technology list & gt; & Lt; Technology & gt; Android.nfc.tech.NfcA & lt; / Tech & gt; & Lt; Technology & gt; Android.nfc.tech.NdefFormatable & lt; / Tech & gt; & Lt; / Tech list & gt; & Lt; / Resources & gt;  
  • Manifest

      & lt; Use-permission Android: name = "android.permission.NFC" /> & lt; Accessibility Android: name = "android.hardware.nfc" /> & Lt; Activity Android: name = ".ui.ScanActivity" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.nfc.action.TECH_DISCOVERED" /> & Lt; Category android: name = "android.intent.category.DEFAULT" /> & Lt; / Intent-Filter & gt; & Lt; Meta-Data Android: name = "android.nfc.action.TECH_DISCOVERED" Android: resource = "@xml / nfc_tech_filter" /> & Lt; / Activity & gt;  
  • Code (activity, some time created after reading the NFC tag)

      intent = getIntent (); If (intention! = Null) {string action = intent.action (); If (NfcAdapter.ACTION_TECH_DISCOVERED.equals (verb)) {parcelable [] rawMsgs = intent.getParcelableArrayExtra (NfcAdapter.EXTRA_NDEF_MESSAGES);               

    The same is true, Reads the same tag, shows the tag in which the tag is where I am wrong

    There are various types of NFC tags (like Mifar Ultralight, Mifar Ultralight C, Mifar Classic, Felica .. .) Each tag has different memory size and reading process. For example: Miffer UltraLite has 64 bytes but the Mifera Classic 1 has 1 kilobyte memory. No additional authentication is required to read data from Mifare Ultralight, but Mifare Classic requirements require authentication. When you get a new intent, you can parse it to get the tag information: First you have to initialize the NFC Adapter and define the pending effect in the Crackback Callback:

      NfcAdapter mAdapter; Pendingending mPendingIntent; MAdapter = NfcAdapter.getDefaultAdapter (this); If (mAdapter == null) {// nfc your device does not support return; } MPendingIntent = PendingIntent.getActivity (this, 0, new intent (this, getClass ()). AddFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);  

    Enable Foreground Dispatch to detect NFC intentions back in onResume ().

      mAdapter.enableForegroundDispatch (this, mPendingIntent, null, null);  

    OnPause (in callback) you have to disable underground transmission:

      if (mAdapter! = Null) {mAdapter.disableForegroundDispatch (this); }  

    OnNewIntent () call method will give you a new NFC intent. After receiving the intent, you will have to parse the intent to locate the card:

      @Override Protected Zero to be newly created (intent to intent) {getTagInfo}} private zero getTagInfo Intent) {tag = intent.getParcelableExtra (NfcAdapter.EXTRA_TAG); }  

    Here is the complete project here to find the exact tag type that you have the tag


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -