Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NFC tags be protected from being overwritten?

Tags:

nfc

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

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!

like image 473
brightreb Avatar asked Apr 14 '11 21:04

brightreb


1 Answers

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:

  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 );
    
  2. From your Tag try to get an Ndef tag object from the intent.

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

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

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

like image 105
Andrew Mackenzie Avatar answered Sep 30 '22 03:09

Andrew Mackenzie