NFC (Near Field Communication) and NDEF (NFC Data Exchange Format) are related technologies used in close-range wireless communication, but they serve different purposes within the NFC ecosystem.
🔹 NFC (Near Field Communication)
Definition:
NFC is a set of short-range wireless communication protocols that allow two electronic devices (like a smartphone and an NFC tag) to communicate when they are brought within about 4 cm (1.6 inches) of each other.
Purpose:
Enables contactless data transfer between devices. Used for things like:
Mobile payments (e.g., Google Pay, Apple Wallet)
Smart posters (tap to get info or open a URL)
Device pairing (Bluetooth, Wi-Fi)
Access control systems
Public transport ticketing
Types of NFC Devices:
NFC Readers (e.g., smartphones)
NFC Tags (passive storage chips)
Peer-to-peer (device-to-device)
Standards:
Based on RFID standards like ISO/IEC 14443 Types A and B.
🔹 NDEF (NFC Data Exchange Format)
Definition:
NDEF is a data format standard used by NFC devices to structure and exchange data in a standardized way.
Purpose:
Defines how information should be formatted so that any NFC-enabled device can understand it — regardless of manufacturer or platform.
Structure:
NDEF messages are made up of one or more NDEF records, each with:
A header (contains flags, type length, payload length)
A type field (describes what kind of data follows)
A payload (the actual data being transmitted)
Common Record Types:
urn:nfc:wkt:U – URI (web address)
urn:nfc:wkt:T – Text
urn:nfc:wkt:Sp – Smart Poster
mime – Custom MIME types (e.g., images, vCards)
Example:
When you tap your phone on an NFC tag that opens a URL, the URL is likely packaged inside an NDEF message with a URI record.
✅ Summary of Differences
Feature
NFC
NDEF
Type
Communication technology
Data format standard
Purpose
Enables short-range wireless communication
Structures the data exchanged via NFC
Scope
Physical layer + protocols
Application-level data structure
Example Use Cases
Payments, access control, Bluetooth pairing
Sending URLs, text, smart posters
Standards
ISO/IEC 18092, ISO/IEC 14443
NFC Forum NDEF specification
🧠 Analogy:
Think of NFC as the postal service system, including trucks, mailboxes, and delivery rules.
NDEF is like the format of the letter you put in the envelope — ensuring that both sender and receiver understand the contents.
Let me know if you'd like examples of NDEF records or how to read/write them!
User
Can you show some examples of NDEF records and how to read them?
Assistant
Absolutely! Let's dive into some examples of NDEF records and how you can read them using common tools or code.
📦 What Is an NDEF Record?
An NDEF record is a structured data unit that NFC devices use to exchange information. It typically includes:
Header byte(s) – flags, message begin/end, type length, payload length
Type name format (TNF) – describes the type field
Type – what kind of data this is (text, uri, etc.)
Payload – the actual data (e.g., a URL, text string)
65 78 61 6D 70 6C 65 2E 63 6F 6D: ASCII for "example.com"
Decoded:
http://www.example.com
🧪 Example 2: Text Record (urn:nfc:wkt:T)
Raw NDEF Bytes:
User
Does it possible to communicate to credit card from Android app?
Assistant
Yes, it is possible to communicate with a credit card (specifically contactless EMV chip cards) from an Android app — but there are important limitations and security restrictions due to the sensitive nature of payment data.
Let’s break this down clearly:
✅ Is It Possible?
Yes:
Many modern credit/debit cards use NFC (contactless payments).
Android devices with NFC hardware can detect these cards and sometimes read basic information like:
Card number (masked)
Expiry date
Card type (Visa, Mastercard, etc.)
However:
⚠️ But With Limitations:
You cannot freely access full card details, CVV, PIN, or transaction history.
Communication is protected by secure protocols like EMVCo standards, encryption, and mutual authentication between the card and the terminal (or phone).
Most cards only allow reading non-sensitive data for anti-cloning and presence verification.
🔐 What Actually Happens?
When you tap your Android phone on a credit card (e.g., using Google Wallet), it doesn’t just "read" the card. Instead:
The phone and card perform a secure cryptographic exchange.
The card generates a one-time cryptogram or tokenized data.
This cryptogram is sent to the payment network (Visa/Mastercard) to verify the transaction.
This process is part of EMV Contactless Payments, and it's highly secured.
📱 Can My App Read Card Info?
If You're Building an App:
You can detect that a card is present via NFC.
You can get limited info like:
Application Identifier (AID)
PAN (partially masked)
Expiry date
You cannot get sensitive data like CVV or PIN.
To Do This:
You need to work in "reader mode" (Android HCE reader or low-level ISO/IEC 14443-4).
🔧 Technical Options
1. Use Host Card Emulation (HCE) – Not what you want
HCE lets your phone act as a card (like Google Pay).
✅ On Android (Java/Kotlin) — Using NdefMessage & NdefRecord
val intent = getIntent()
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
val ndef = Ndef.get(tag)
if (ndef != null) {
val ndefMessage = ndef.cachedNdefMessage
for (record in ndefMessage.records) {
when (record.tnf) {
NdefRecord.TNF_WELL_KNOWN -> {
if (Arrays.equals(record.type, NdefRecord.RTD_URI)) {
val uri = String(record.payload.copyOfRange(1, record.payload.size))
Log.d("NFC", "URI: http://$uri")
}
if (Arrays.equals(record.type, NdefRecord.RTD_TEXT)) {
val language = String(record.payload, 0, 1)
val text = String(record.payload, 1, record.payload.size - 1)
Log.d("NFC", "Text ($language): $text")
}
}
}
}
}
✅ On iOS (Swift) — Using Core NFC
import CoreNFC
class NFCReaderDelegate: NSObject, NFCNDEFReaderSessionDelegate {
func readerSession(_ session: NFCNDEFReaderSession, didDetect records: [NFCNDEFRecord]) {
for record in records {
if let payload = String(data: record.payload, encoding: .utf8) {
print("Payload: $payload)")
}
}
}
}
✅ Using Command Line Tools — nfc-read-forum-tag (libnfc)
If you're on Linux with an NFC reader like ACR122U:
nfc-read-forum-tag
This will show NDEF records in human-readable form.
✅ Using Apps
Android: NFC Tools, Trigger, NXP TagWriter
iOS: Shortcuts app (built-in NFC support), or apps like NFC Tools
🛠 Bonus: Writing NDEF Records
Here’s how to write a simple URI record to a tag in Android:
val uriRecord = NdefRecord.createUri("https://example.com")
val message = NdefMessage(uriRecord)
val ndef = Ndef.get(tag)
ndef.connect()
ndef.writeNdefMessage(message)
ndef.close()
🧾 Summary
Task
Tool/Method
Read NDEF on Android
Use NdefMessage and NdefRecord
Read NDEF on iOS
Use Core NFC
Read NDEF via PC
Use libnfc tools (Linux)
View NDEF visually
Use apps like NXP TagWriter or NFC Tools
Write NDEF
Use writeNdefMessage() or tools
Would you like help building a sample app or reading/writing NDEF from a specific platform (like Python or Node.js)?
You're trying to read a card, not emulate one.
2. Use Low-Level NFC APIs
Use NfcA, IsoDep tags in Android to talk directly to the card.
Example:
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
val isoDep = IsoDep.get(tag)
if (isoDep != null) {
isoDep.connect()
val response = isoDep.transceive(selectApdu) // Send SELECT command
Log.d("NFC", "Response: ${response.toHexString()}")
isoDep.close()
}
Note: You’ll need to send APDUs (Application Protocol Data Units) according to EMV standards.
Cards use mutual authentication and encrypted channels.
Android does not give direct access to secure elements (like embedded SE or SIM-based SE) unless you have special permissions or certifications.
Payment networks (Visa, Mastercard) do not allow arbitrary apps to extract card data.
🧪 Real-World Use Cases
Goal
Feasible?
Notes
Detect card presence
✅ Yes
Easy via NFC
Read partial card info
✅ Limited
Only non-sensitive fields
Make a payment
✅ Yes
Use Google Pay or integrated payment SDKs
Clone card / extract key material
❌ No
Illegal and technically blocked
Build own payment app
✅ But hard
Requires certification with payment networks
✅ Alternative: Use Google Pay or Payment Gateways
If your goal is to accept payments, consider:
Integrate with Google Pay API or services like:
Stripe
Adyen
Square
PayPal
They abstract away all the complexity and provide secure, compliant payment flows.
📝 Summary
Question
Answer
Can I communicate with a credit card from an Android app?
✅ Yes, over NFC
Can I read full card details (PAN, CVV, PIN)?
❌ No, restricted by encryption and security
Can I make payments from my app?
✅ Yes, via Google Pay or payment gateways
Can I build my own NFC payment app?
⚠️ Yes, but requires EMV certification and compliance
Would you like help writing code to detect and read basic info from a contactless card using Android? Or are you looking to integrate payments into your app securely?