The Nexus S can write to NFC tags. How do you stop anyone with a Nexus S from overwriting your tag?
开发者_JAVA技巧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?
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.
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.
This is all described in the developer documentation for NFC classes on the Android developer site.
For example, if you are working at higher level and reading/writing Ndef
messages:
Setup an intent filter (in code or manifest) so you detect
Ndef
orNDefFormatable
tags. You can get aTag
object from theIntent
passed to you (inonCreate()
oronNewIntent()
).Tag tag = intent.getParcelableExtra( NfcAdapter.EXTRA_TAG );
From your
Tag
try to get anNdef
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 themakeReadOnly()
ofNdef
....If getting an
Ndef
object failed (exception) then you will need to format the Tag first....so... get anNdefFormattable
object from the detectedTag
and write a message to it and protect it, using theformatReadOnly(NdefMessage firstMessage)
, or just format it and then continue with code to getNdef
...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.
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.
Some NFC Tags can be configured to be read-only. Some are purchased with your data on them already, and set to read-only. http://www.radio-electronics.com/info/wireless/nfc/near-field-communications-tags-types.php
Yes, you can write-protect (most) tags, which inhibits others from overwriting your content. If you just want to write a tag, a good android app is NXP tagwriter, which has a variety of encoding options and a write-protect option.
If you want to make it so only you have control of your tag's content, try NFCLabels tag manager app. Your tag content is stored in the 'cloud', and you access your tag through your account. So you can write-protect a tag so Joe Schmoe can't blast your content, but you still have freedom to update your tag as needed. It also gives you some basic engagement analytics. Their youtube video shows how it works (see above link.)
Almost all of nfc tags can be protected by locked bits, which you can write an NFC tags with apps like NXP tagwriter, tasklauncher, make sure you have choose readonly options for encoding. Beside attention if an tag is read-only, it can not be rewritten again. For apps or nfc tags, go geenfc website for details.
精彩评论