Exemple #1
0
 public static NdefRecord[] readRecords(Tag tag)
     throws IOException, FormatException, NotReadableException {
   Ndef ndefTag = Ndef.get(tag);
   if (ndefTag == null) {
     throw new NotReadableException("The tag doesn't support Ndef tech");
   }
   ndefTag.connect();
   NdefMessage message = ndefTag.getNdefMessage();
   NdefRecord[] records = message.getRecords();
   ndefTag.close();
   return records;
 }
Exemple #2
0
 public static String[] readStrings(Tag tag)
     throws IOException, FormatException, NotReadableException {
   Ndef ndefTag = Ndef.get(tag);
   if (ndefTag == null) {
     throw new NotReadableException("The tag doesn't support Ndef tech");
   }
   ndefTag.connect();
   NdefMessage message = ndefTag.getNdefMessage();
   NdefRecord[] records = message.getRecords();
   String[] out = new String[records.length];
   int i = 0;
   for (NdefRecord rec : records) {
     out[i++] = new String(rec.getPayload(), Charset.forName("UTF-8"));
   }
   ndefTag.close();
   return out;
 }