Handling tag-reading errors
In this recipe, we will implement generic validation methods to identify the tag format. This way, we can implement different payload handling mechanisms for the content that our application knows to handle, preventing unwanted exceptions.
Getting ready
We will be using the project from the previous recipe, so make sure you have gone through it before starting this one.
How to do it...
In this application, we will be adding some methods to your NfcHelper
class to facilitate the identification of the tag content. To do this, perform the following steps:
Open the project files from the Handling tag-writing errors recipe.
Implement the
isTextRecord
method in theNfcHelper
class with the following code:public boolean isTextRecord(NdefRecord record) { if (record == null) { return false; } return isNdefRecordOfTnfAndRdt(record, NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT); }
Implement the
isUrlRecord
method in theNfcHelper
class:public boolean...