Search code examples
androidxamarinnfcmifarendef

How can I act with Android app as MIFARE card?


How can I send an NDEF message from phone to MIFARE card reader?

On the reader side I use this code from https://github.com/AlterCodex/nxppy:

import nxppy
import ndef

# Instantiate reader
mifare = nxppy.Mifare()

# Select tag
uid = mifare.select()

# Read NDEF data
ndef_data = mifare.read_ndef()

# Parse NDEF data
ndef_records = list(ndef.message_decoder(ndef_data))

When I try to send an NDEF message with this code I get memory error:

    public NdefMessage CreateNdefMessage(NfcEvent e)
    {
        NdefRecord uriRecord = NdefRecord.CreateUri("http://myURL");
        NdefMessage message = new NdefMessage(new[] { uriRecord });
        return message;
    }

For this code I am getting error: ndef_data = milfare.read_ndef() MemoryError.

How can I edit this solution to make it work? I just want to read a simple NDEF message from Android application with nfc-explorer board but I am completly confused how to do this.


Solution

  • The mifare.read_ndef() seems to expect a MIFARE Ultralight (or other Type 2 tag) containing an NDEF message. You simply can't emulate a MIFARE (Ultralight) tag with Android (see Emulate Mifare card with Android 4.4).

    What you do on Android, when you use public NdefMessage CreateNdefMessage(NfcEvent e) {} (or actually SetNdefPushMessage*()), is that you define an NDEF message that should be transfered in peer-to-peer mode (using SNEP + LLCP + NFC-DEP). That's a completely different protocol stack than when you read (or emulate) a tag. Consequently, when you want to use peer-to-peer mode on Android, you will need to use a library that supports peer-to-peer mode (and SNEP) on the other end as well.