Code example for NdefMessage

Methods: toByteArray

        //So the MimeType is here.. not sure whats going on.. will research. 
        byte[] mimeBytes = MimeType.NFC.getBytes(Charset.forName("US-ASCII"));
        NdefRecord cardRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes,
                new byte[0], payload);
        NdefMessage message = new NdefMessage(new NdefRecord[] { cardRecord, appRecord});
        try { 
            // see if tag is already NDEF formatted 
            Ndef ndef = Ndef.get(tag);
            if (ndef != null) {
                if (!ndef.isWritable()) {
                    displayMessage("Read-only tag."); 
                    return false; 
                // work out how much space we need for the data 
                int size = message.toByteArray().length;
                if (ndef.getMaxSize() < size) {
                    displayMessage("Tag doesn't have enough free space."); 
                    return false; 
Stop searching for code, let great code find you!  Add Codota to your java IDE