Nexus S可以写入NFC标签。 如何防止任何使用Nexus S的人覆盖您的标签?
例如,如果您在传单上放置了一个启动视频的NFC标签,那么是否有人可以使用Nexus S将其覆盖并替换为指向他网站的链接?
我是初学者,只是想了解一下NFC,请多多关照!
Nexus S可以写入NFC标签。 如何防止任何使用Nexus S的人覆盖您的标签?
例如,如果您在传单上放置了一个启动视频的NFC标签,那么是否有人可以使用Nexus S将其覆盖并替换为指向他网站的链接?
我是初学者,只是想了解一下NFC,请多多关照!
许多标签类型都支持写保护,有些是全局的,而其他更复杂的标签则通过标签内存区域实现。
当您在Android NFC应用程序中检测到您的标签时,您可以获取一个Tag对象,并读取和写入标签,包括保护它免受进一步的写入。
这些都在Android开发者网站上的NFC类的开发者文档中描述。
例如,如果您正在高级别上工作并且正在读/写Ndef消息:
Setup an intent filter (in code or manifest) so you detect Ndef
or NDefFormatable
tags. You can get a Tag
object from the Intent
passed to you (in onCreate()
or onNewIntent()
).
Tag tag = intent.getParcelableExtra( NfcAdapter.EXTRA_TAG );
From your Tag
try to get an Ndef
tag object from the intent.
If successful in getting an Ndef
object from the tag, then check it is writable, check it has enough space, write to it and then use the makeReadOnly()
of Ndef
....
If getting an Ndef
object failed (exception) then you will need to format the Tag first....so...
get an NdefFormattable
object from the detected Tag
and write a message to it and protect it, using the formatReadOnly(NdefMessage firstMessage)
, or just format it and then continue with code to get Ndef
...
If you can't get an NdefFormattable
object then something is seriously wrong, as that was what you requested in your filter. Formatting might fail if it is read-only already.
一旦您理解了如何通过“标签技术”(包括NdefFormatable
和Ndef
)设置IntentFilter
并从基本标签获取这些对象以执行不同操作,开发者文档就不太困难。
一些NFC标签可以配置为只读模式。 有些标签已经预先存储了数据并设置为只读模式。 http://www.radio-electronics.com/info/wireless/nfc/near-field-communications-tags-types.php
是的,你可以写保护(大多数)标签,防止其他人覆盖你的内容。如果你只想写一个标签,一个好用的安卓应用是NXP tagwriter,它具有多种编码选项和写保护选项。
如果你想让只有你控制标签的内容,请尝试NFCLabels tag manager应用程序。你的标签内容存储在“云”中,你通过账户访问你的标签。因此,你可以写保护标签,使Joe Schmoe无法破坏你的内容,但你仍然可以根据需要自由更新你的标签。它还提供了一些基本的参与分析功能。他们的YouTube视频展示了它的工作原理(请见上面的链接)。