How to format an NFC tag in NDEF format

2019-03-30 00:42发布

I've a Mifare Classic1K NFC tag but I'm unable to write any content over it. Its writable but seems like it is not formatted in NDEF which is a pre-requisite for Android devices to be write data on it. Any suggestion is welcome.

P.S: I do have a TRF7960 RF Antenna if that can help to format it.

标签: android nfc
1条回答
在下西门庆
2楼-- · 2019-03-30 01:15

Given an android.nfc.Tag object named tag, to format it, use:

    NdefFormatable formatable=NdefFormatable.get(tag);

    if (formatable != null) {
      try {
        formatable.connect();

        try {
          formatable.format(msg);
        }
        catch (Exception e) {
          // let the user know the tag refused to format
        }
      }
      catch (Exception e) {
        // let the user know the tag refused to connect
      }
      finally {
        formatable.close();
      }
    }
    else {
      // let the user know the tag cannot be formatted
    }
查看更多
登录 后发表回答