可以保护NFC标签不被覆盖吗? [英] Can NFC tags be protected from being overwritten?

查看:209
本文介绍了可以保护NFC标签不被覆盖吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Nexus S可以写入NFC标签.如何阻止使用Nexus S的任何人覆盖您的代码?

The Nexus S can write to NFC tags. How do you stop anyone with a Nexus S from overwriting your tag?

例如如果在发布视频的传单上贴有NFC标签,那么拥有Nexus S的人是否可以覆盖该标签并将其替换为指向他网站的链接?

eg. If you have an NFC tag on a flyer that launches a video, can a guy with a Nexus S overwrite it and replace it with a link to his website?

这里的初学者,只是想了解NFC,谢谢!

Beginner here, just trying to get a handle on NFC, thanks!

推荐答案

是的,很多标记类型都允许写保护,某些可以全局保护,而其他更复杂的则可以通过标记中的内存部分实现.

Yes, many tag types permit write protection, some globally, and other more sophisticated ones by memory section inside the tag.

当您在Android NFC应用中检测到标签时,便可以获取Tag对象并读取和写入标签,包括保护标签免于进一步写入.

When you get your tag detected in your Android NFC app, then you can get a Tag object and read and write to the tag, including protecting it from further writing.

所有这些都在Android开发人员网站上有关NFC类的开发人员文档中进行了描述.

This is all described in the developer documentation for NFC classes on the Android developer site.

例如,如果您在更高级别上工作并读取/编写Ndef消息:

For example, if you are working at higher level and reading/writing Ndef messages:

  1. 设置一个意图过滤器(在代码或清单中),以便检测NdefNDefFormatable标记.您可以从传递给您的Intent中获取一个Tag对象(在onCreate()onNewIntent()中).

  1. 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 );

  • 从您的Tag中尝试获取 标签对象.

  • From your Tag try to get an Ndef tag object from the intent.

    如果成功从标记中获取了Ndef对象,则检查其是否可写,检查其是否具有足够的空间,写入该对象,然后使用NdefmakeReadOnly() ....

    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....

    如果获取Ndef对象失败(异常),则需要首先格式化标签.... so ... 从检测到的Tag获取 NdefFormattable 对象,然后使用formatReadOnly(NdefMessage firstMessage)向其中写入消息并加以保护,或者只是对其进行格式化,然后继续执行代码以获取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 ...

    如果无法获取NdefFormattable对象,则说明存在严重错误,因为这是您在过滤器中所请求的.如果格式已经是只读的,则格式化可能会失败.

    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.

    开发人员文档还不错,一旦您开始通过"Tag Technology"(包括NdefFormatableNdef)设置IntentFilter,然后从基本Tag中获取这些对象以执行不同的操作

    The developer documentation is not too bad, once you get your head around setting the IntentFilter by "Tag Technology" (including NdefFormatable and Ndef) and then getting those objects from the base Tag to do different operations.

    这篇关于可以保护NFC标签不被覆盖吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆