Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.os.Parcelable;

public class Main {
    public static String getNFCString(Parcelable[] rawMessages) {
        if (rawMessages != null && rawMessages.length == 1) {
            NdefMessage message = (NdefMessage) rawMessages[0];
            NdefRecord[] records = message.getRecords();
            if (records.length == 1) {
                byte[] payload = records[0].getPayload();

                //convert byte array to string, throw out first 3 characters (see http://stackoverflow.com/questions/7917567/strange-character-on-android-ndef-record-payload)
                return new String(payload).substring(3);
            }
        }

        return null;
    }
}