How to format an NFC tag in NDEF format

僤鯓⒐⒋嵵緔 提交于 2020-01-12 08:38:29

问题


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.


回答1:


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
    }


来源:https://stackoverflow.com/questions/13970931/how-to-format-an-nfc-tag-in-ndef-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!