Skip to content

Instantly share code, notes, and snippets.

Created November 8, 2017 16:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
NdefMessageParser class for the NFC Reader Tutorial
* Copyright (C) 2010 The Android Open Source Project
* Modified by Sylvain Saurel for a tutorial
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
package com.ssaurel.nfcreader.parser;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import com.ssaurel.nfcreader.R;
import com.ssaurel.nfcreader.model.History;
import com.ssaurel.nfcreader.record.ParsedNdefRecord;
import com.ssaurel.nfcreader.record.SmartPoster;
import com.ssaurel.nfcreader.record.TextRecord;
import com.ssaurel.nfcreader.record.UriRecord;
import com.ssaurel.nfcreader.utils.NFCReaderApp;
import java.util.ArrayList;
import java.util.List;
public class NdefMessageParser {
private NdefMessageParser() {
public static List<ParsedNdefRecord> parse(NdefMessage message) {
return getRecords(message.getRecords());
public static List<ParsedNdefRecord> getRecords(NdefRecord[] records) {
List<ParsedNdefRecord> elements = new ArrayList<ParsedNdefRecord>();
for (final NdefRecord record : records) {
if (UriRecord.isUri(record)) {
} else if (TextRecord.isText(record)) {
} else if (SmartPoster.isPoster(record)) {
} else {
elements.add(new ParsedNdefRecord() {
public String str() {
return new String(record.getPayload());
return elements;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment