Nfc标签上的ID是否不唯一? [英] Id on Nfc tag not unique?
问题描述
我正在读取android手机上的nfc标签,我写给标签的值是这样写的:
I am reading nfc tags on android phone, there is value which I written to the tag which I read like this:
@Override
protected String doInBackground(Tag... params) {
Tag tag = params[0];
Ndef ndef = Ndef.get(tag);
if (ndef == null) {
// NDEF is not supported by this Tag.
return null;
}
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
NdefRecord[] records = ndefMessage.getRecords();
for (NdefRecord ndefRecord : records) {
if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
try {
return readText(ndefRecord);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupported Encoding", e);
}
}
}
return null;
}
private String readText(NdefRecord record) throws UnsupportedEncodingException {
byte[] payload = record.getPayload();
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16"; // Get the Text Encoding
int languageCodeLength = payload[0] & 0063; // Get the Language Code
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding); // Get the Text
}
我尝试过,并且应该有一个只读的NfcTag唯一ID:
And there should be a unique Id of the NfcTag which is read only, I tried:
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
mNfcId = tag.getId().toString();
但这在下次阅读时给出了不同的结果!!! 如何从nfc标签读取唯一的只读标签?
But this is giving different results on next read !!! How can I read the unique read only tag from nfc Tag ?
推荐答案
出于隐私原因,有些标签没有唯一的ID.大多数包含NFC芯片的旅行证件和信用卡都在其中.
There are tags that don't have a unique ID for privacy reasons. Most travel documents and credit cards that contain an NFC chip are among them.
也:不要指望您可以读取的ID的唯一性.这些很容易被伪造.同样,许多NFC标签制造商也不保证ID的全球唯一性.
Also: Don't count on the uniqueness of the IDs you can read. These can easily be faked. Also many manufacturers of NFC tags don't guarantee the worldwide uniqueness of the ID.
这篇关于Nfc标签上的ID是否不唯一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!