无法格式化用NdefFormatable NFC卡 [英] Not able to format NFC card using NdefFormatable
问题描述
我使用NdefFormatable类格式化我NFC卡。在code是这样的:
I am using NdefFormatable class to format my NFC card. The code is like:
NdefFormatable formatable=NdefFormatable.get(tag);
但我得到formatable引用为空。我查了是Get(标签)方法中运行code。它会检查:
But i get formatable reference as null. I checked the code that is run inside the get(tag) method. It checks:
if (!tag.hasTech(TagTechnology.NDEF_FORMATABLE)) return null;
我跑的tag.getTechList()的我的标签。我:
android.nfc.tech.NfcA
android.nfc.tech.Ndef
我能够使用格式化程序触发此卡。
I was able to format this card using Trigger application.
可以做些什么来格式化这个。
What can be done to format this.
推荐答案
在 NdefFormatable
和 NDEF
标签技术是相互排斥的。或者您的标签还没有NDEF格式(即它是尚未prepared存储的NDEF消息)或它已经$ ppared存储的NDEF消息p $(和已经包含(至少一个空的)一个NDEF消息)。
The NdefFormatable
and the Ndef
tag technologies are mutually exclusive. Either your tag is not yet NDEF formatted (i.e. it is not yet prepared to store NDEF messages) or it is already prepared to store NDEF messages (and already contains (at least an empty) an NDEF message).
所以 NdefFormatable
仅用于编写初步NDEF消息标签。
So NdefFormatable
is only used for writing an initial NDEF message to a tag.
由于您的标记已经列出了 android.nfc.tech.Ndef
的技术,它已经$ ppared存储的NDEF消息p $,不需要进一步的格式。你可以简单地覆盖(因为标签是不是只读)任何现有的NDEF使用 NDEF的
writeNdefMessage()
方法消息code>对象。例如。到格式标签为空NDEF消息,你可以这样做:
As your tag already lists the android.nfc.tech.Ndef
technology, it is already prepared to store an NDEF message and does not need further formatting. You can simply overwrite (given that the tag is not read-only) any existing NDEF message by using the writeNdefMessage()
method of the Ndef
object. E.g. to "format" the tag to an empty NDEF message, you could do something like:
Ndef ndefTag = Ndef.get(tag);
ndefTag.writeNdefMessage(new NdefMessage(new NdefRecord(NdefRecord.TNF_EMPTY, null, null, null)));
更新:
在与libnfc-NCI NFC协议栈设备,似乎 NdefFormatable
和 NDEF
标签技术不再是相互排斥的。格式化标签将(有时?)枚举为两个 NdefFormatable
和 NDEF
。在放入系统的情况下,你仍然会通常尝试第一个也是唯一使用 NDEF如果失败使用
NdefFormatable
对象。
Update:
On devices with the libnfc-nci NFC stack, it seems that NdefFormatable
and Ndef
tag technologies are no longer mutually exclusive. Formatted tags will (sometimes?) be enumerated as both NdefFormatable
and Ndef
. In thoses cases, you would still typically try to use the Ndef
first and only if that fails use the NdefFormatable
object.
这篇关于无法格式化用NdefFormatable NFC卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!