Why I'm Getting Ioexception When Making Nfc Tag Read Only
Solution 1:
Browsing through the Android 4.4.2 source (I did not check with older versions) reveals that you will always get an IOException
if makeReadOnly()
fails for whatever reason. So you found a bug in Android or at least a mismatch with the API documentation.
The cause is that android.nfc.tech.Ndef
(see here, starting on line 383) expects the NFC service to return ErrorCodes.SUCCESS
for successful locking, ErrorCodes.ERROR_INVALID_PARAM
for failed locking and ErrorCodes.ERROR_IO
on any IO related error. However, the NFC service returns ErrorCodes.SUCCESS if locking succeeds (see here, line 1438) and ErrorCodes.ERROR_IO if locking fails for any reason (see here, line 1440). ErrorCodes.ERROR_INVALID_PARAM
seems not to be returned at all, thus the makeReadOnly()
method should typically never return false
.
Post a Comment for "Why I'm Getting Ioexception When Making Nfc Tag Read Only"