<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sushil Kumar Prajapat</title>
    <description>The latest articles on Forem by Sushil Kumar Prajapat (@sky1309).</description>
    <link>https://forem.com/sky1309</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3767870%2Fd7e06d80-911c-419f-b94f-63c4875e095b.png</url>
      <title>Forem: Sushil Kumar Prajapat</title>
      <link>https://forem.com/sky1309</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sky1309"/>
    <language>en</language>
    <item>
      <title>🟢 Part 2: Android HCE Implementation — Build a Complete Type 4 NFC Tag with HostApduService</title>
      <dc:creator>Sushil Kumar Prajapat</dc:creator>
      <pubDate>Tue, 17 Feb 2026 05:06:31 +0000</pubDate>
      <link>https://forem.com/sky1309/part-2-android-hce-implementation-build-a-complete-type-4-nfc-tag-with-hostapduservice-1ka7</link>
      <guid>https://forem.com/sky1309/part-2-android-hce-implementation-build-a-complete-type-4-nfc-tag-with-hostapduservice-1ka7</guid>
      <description>&lt;h2&gt;
  
  
  🚀 Introduction
&lt;/h2&gt;

&lt;p&gt;In Part 1 we explored the architecture behind Android Host-Based Card Emulation (HCE), ISO-DEP, and APDU structure. In this Part 2, you will build a complete Android HCE implementation step-by-step using HostApduService, handling SELECT, READ, and response logic to emulate an NFC Type 4 Tag in Kotlin.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔵 1. Android HCE Architecture
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reader → NFC Controller → Android OS → HostApduService → Response APDU
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 2. Project Setup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Android Studio&lt;/li&gt;
&lt;li&gt;Min SDK 19+&lt;/li&gt;
&lt;li&gt;Target SDK 36&lt;/li&gt;
&lt;li&gt;Kotlin (recommended)&lt;/li&gt;
&lt;li&gt;Required permissions (uses NFC)&lt;/li&gt;
&lt;li&gt;Emulator vs physical device note (NFC only works on real devices)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: NFC HCE cannot be tested on many emulators — use a physical device with NFC support.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🔵 3. Create HostApduService
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyHostApduService : HostApduService() {
 // Status Word on success (used in response)
    private val SUCCESS_SW = byteArrayOf(0x90.toByte(), 0x00.toByte())

    // Status Word in case of failure (used in response)
    private val FAILURE_SW = byteArrayOf(0x6a.toByte(), 0x82.toByte())
    override fun processCommandApdu(
        commandApdu: ByteArray?,
        extras: Bundle?
    ): ByteArray {

        if (commandApdu == null) return FAILURE_SW
        /*This block handles the SELECT command for the NDEF 
          application AID. When the NFC reader selects this AID, we 
          respond with 90 00 (success).*/
        // Match incoming APDU to SELECT Application AID
        if (commandApdu.contentEquals(SELECT_APP)) {
            return SUCCESS_SW
        }
         /*This block handles the SELECT command for the NDEF 
          application Capability Container. 
          When the NFC reader selects this CC, we 
          respond with 90 00 (success).*/
        // Match incoming APDU to SELECT CC File
        if (commandApdu.contentEquals(SELECT_CC)) {
            return SUCCESS_SW
        }

        return FAILURE_SW
    }

    override fun onDeactivated(reason: Int) {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  💠 Lifecycle Diagram
&lt;/h4&gt;

&lt;p&gt;how HostApduService methods are called:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgvctirj8c00th0gup8ge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgvctirj8c00th0gup8ge.png" alt=" " width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Android routes incoming ISO-DEP APDU commands to processCommandApdu() inside your HostApduService, where your logic determines the response.&lt;/p&gt;
&lt;h4&gt;
  
  
  💠 Flow Chart
&lt;/h4&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8c6rp5b9rlljnh4tr6af.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8c6rp5b9rlljnh4tr6af.png" alt=" " width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your implementation must follow this sequence to correctly emulate a Type 4 NFC Tag and avoid communication failures.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🔵 4. apduservice.xml
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;host-apdu-service
    android:description="@string/app_name"
    android:requireDeviceUnlock="false"&amp;gt;

    &amp;lt;aid-group android:category="other"&amp;gt;
        &amp;lt;aid-filter android:name="D2760000850101"/&amp;gt;
    &amp;lt;/aid-group&amp;gt;

&amp;lt;/host-apdu-service&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 5. AndroidManifest
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;service
    android:name=".MyHostApduService"
    android:permission="android.permission.BIND_NFC_SERVICE"
    android:exported="true"&amp;gt;

    &amp;lt;intent-filter&amp;gt;
        &amp;lt;action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/&amp;gt;
    &amp;lt;/intent-filter&amp;gt;

    &amp;lt;meta-data
        android:name="android.nfc.cardemulation.host_apdu_service"
        android:resource="@xml/apduservice"/&amp;gt;
&amp;lt;/service&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 6. Implement CC File Response
&lt;/h3&gt;

&lt;p&gt;When receiving:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CLA = 0x00
INS = 0xB0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return CC file bytes + 90 00.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔵 7. Return NLEN
&lt;/h3&gt;

&lt;p&gt;If LE == 2:&lt;/p&gt;

&lt;p&gt;Return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NLEN + 90 00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 8. Return NDEF Data
&lt;/h3&gt;

&lt;p&gt;Return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NLEN + NDEF Message + 90 00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 9. Security Considerations
&lt;/h3&gt;

&lt;p&gt;HCE is software-based.&lt;/p&gt;

&lt;p&gt;Important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not hardware-secure like Secure Element&lt;/li&gt;
&lt;li&gt;Encrypt sensitive payload&lt;/li&gt;
&lt;li&gt;Validate on backend&lt;/li&gt;
&lt;li&gt;Prevent replay attacks&lt;/li&gt;
&lt;li&gt;Add timeout/session control&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔵 10. Full Communication Sequence Diagram
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reader                     Android HCE
  │                              │
  │ --- SELECT AID ------------&amp;gt; │
  │ &amp;lt;--- 90 00 ----------------- │
  │ --- SELECT CC --------------&amp;gt;│
  │ &amp;lt;--- 90 00 ------------------│
  │ --- READ CC ----------------&amp;gt;│
  │ &amp;lt;--- CC DATA + 90 00 ------- │
  │ --- SELECT NDEF ------------&amp;gt;│
  │ &amp;lt;--- 90 00 ------------------│
  │ --- READ NLEN --------------&amp;gt;│
  │ &amp;lt;--- NLEN + 90 00 ---------- │
  │ --- READ NDEF --------------&amp;gt;│
  │ &amp;lt;--- DATA + 90 00 ---------- │

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Forgetting to respond with correct status words&lt;/li&gt;
&lt;li&gt;Not handling unknown APDU commands&lt;/li&gt;
&lt;li&gt;Testing only on emulator (HCE requires real NFC hardware)&lt;/li&gt;
&lt;li&gt;Not validating APDU length before parsing&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🏁 Final Thoughts
&lt;/h3&gt;

&lt;p&gt;In this article, we built a complete Android HCE Type 4 Tag implementation using HostApduService and handled the full APDU exchange sequence.&lt;/p&gt;

&lt;p&gt;Host-Based Card Emulation allows Android to behave like a Type 4 NFC smart card using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ISO 14443-4&lt;/li&gt;
&lt;li&gt;ISO 7816-4&lt;/li&gt;
&lt;li&gt;APDU communication&lt;/li&gt;
&lt;li&gt;NDEF file structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this knowledge, you can build:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access control apps&lt;/li&gt;
&lt;li&gt;Enterprise NFC solutions&lt;/li&gt;
&lt;li&gt;Identity systems&lt;/li&gt;
&lt;li&gt;IoT pairing solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're building NFC or HCE-based systems and have questions, drop them in the comments — I’d love to discuss and help.&lt;/p&gt;

&lt;p&gt;This concludes the 2-part deep dive into Android HCE.&lt;/p&gt;

</description>
      <category>androiddev</category>
      <category>mobile</category>
      <category>nfc</category>
      <category>hce</category>
    </item>
    <item>
      <title>🟢 Android HCE Deep Dive: ISO-DEP, APDU &amp; NFC Type 4 Tag Architecture (Part 1)</title>
      <dc:creator>Sushil Kumar Prajapat</dc:creator>
      <pubDate>Thu, 12 Feb 2026 09:46:03 +0000</pubDate>
      <link>https://forem.com/sky1309/android-hce-deep-dive-iso-dep-apdu-nfc-type-4-tag-architecture-part-1-46ed</link>
      <guid>https://forem.com/sky1309/android-hce-deep-dive-iso-dep-apdu-nfc-type-4-tag-architecture-part-1-46ed</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article gives you the foundational knowledge you need to build production-grade NFC applications on Android — a topic often glossed over in basic tutorials.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;why a developer should care&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;what problem they’ll solve by reading this&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;In this article, you’ll learn how NFC works under the hood — from protocol layers to real card emulation structures — so you can confidently build production-ready Android HCE solutions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Host-based card emulation (HCE) turns an Android device into a contactless smart card without requiring secure hardware. This is the same technology behind mobile payments, access control, and NFC-based identity systems. In this article, you’ll learn how HCE works at the protocol level — from ISO-DEP and APDU to the Type 4 Tag architecture — so you can build reliable, production-ready Android NFC systems.&lt;/p&gt;

&lt;p&gt;This is the same underlying technology used in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mobile payments&lt;/li&gt;
&lt;li&gt;Access control systems&lt;/li&gt;
&lt;li&gt;Digital identity cards&lt;/li&gt;
&lt;li&gt;Smart ticketing&lt;/li&gt;
&lt;li&gt;Enterprise badge systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we’ll deeply explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NFC architecture layers&lt;/li&gt;
&lt;li&gt;ISO-DEP protocol&lt;/li&gt;
&lt;li&gt;APDU command structure&lt;/li&gt;
&lt;li&gt;NFC Forum Type 4 Tag&lt;/li&gt;
&lt;li&gt;NDEF file system structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a technical deep dive for intermediate and advanced Android developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔵 1. NFC Architecture Explained
&lt;/h3&gt;

&lt;p&gt;Although NFC doesn’t strictly follow the OSI model, it can be logically understood in three layers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----------------------------+
|      Application Layer     |
|  (NDEF, Smart Card Logic)  |
+----------------------------+
|       Data Link Layer      |
|  (ISO-DEP, Error Control)  |
+----------------------------+
|       Physical Layer       |
|  (RF 13.56 MHz, NFC-A/B)   |
+----------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Physical Layer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;13.56 MHz RF communication&lt;/li&gt;
&lt;li&gt;NFC-A / NFC-B modulation&lt;/li&gt;
&lt;li&gt;Handles signal transmission&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Data Link Layer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ISO 14443-4 (ISO-DEP)&lt;/li&gt;
&lt;li&gt;Frame structure&lt;/li&gt;
&lt;li&gt;Error detection&lt;/li&gt;
&lt;li&gt;Reliable data transfer&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Application Layer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NDEF (NFC Data Exchange Format)&lt;/li&gt;
&lt;li&gt;APDU commands&lt;/li&gt;
&lt;li&gt;Smart card logic&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔵 2. What is ISO-DEP?
&lt;/h3&gt;

&lt;p&gt;ISO-DEP (ISO 14443-4) is a higher-level NFC protocol that enables structured communication using APDUs.&lt;/p&gt;

&lt;p&gt;It builds on top of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NFC-A&lt;/li&gt;
&lt;li&gt;NFC-B&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why ISO-DEP Matters?&lt;/strong&gt;&lt;br&gt;
Because Android HCE only supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ISO-DEP based card emulation&lt;/li&gt;
&lt;li&gt;APDU command processing
Without ISO-DEP → No HCE.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  🔵 3. Understanding APDU (ISO 7816-4)
&lt;/h3&gt;

&lt;p&gt;APDU (Application Protocol Data Unit) is the communication format between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reader ↔ Smart Card&lt;/li&gt;
&lt;li&gt;NFC Terminal ↔ Android HCE&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;APDU Command Structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CLA | INS | P1 | P2 | LC | DATA | LE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Field&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Meaning&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CLA&lt;/td&gt;
&lt;td&gt;Class byte&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;INS&lt;/td&gt;
&lt;td&gt;Instruction (Select, Read, Update)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;P1/P2&lt;/td&gt;
&lt;td&gt;Parameters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LC&lt;/td&gt;
&lt;td&gt;Length of command data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DATA&lt;/td&gt;
&lt;td&gt;Payload&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LE&lt;/td&gt;
&lt;td&gt;Expected response length&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;APDU Response Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATA | SW1 | SW2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;SW1 SW2&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;90 00&lt;/td&gt;
&lt;td&gt;Success&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6A 82&lt;/td&gt;
&lt;td&gt;File not found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6A 86&lt;/td&gt;
&lt;td&gt;Incorrect parameters&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Common status words.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔵 4. NFC Forum Type 4 Tag Architecture
&lt;/h3&gt;

&lt;p&gt;Type 4 Tag is built on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ISO-DEP&lt;/li&gt;
&lt;li&gt;APDU communication&lt;/li&gt;
&lt;li&gt;File-based system (ISO 7816)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;🧩 Type 4 Tag File System&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In Type 4 Tags, the Capability Container (CC) file tells the reader how the tag is structured, and the NDEF file contains the actual NFC data.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NDEF Tag Application (AID)
│
├── CC File (E103)
│
└── NDEF File (E104)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 5. Capability Container (CC) File
&lt;/h3&gt;

&lt;p&gt;The CC file defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mapping version&lt;/li&gt;
&lt;li&gt;Maximum read size (MLe)&lt;/li&gt;
&lt;li&gt;Maximum write size (MLc)&lt;/li&gt;
&lt;li&gt;NDEF file identifier&lt;/li&gt;
&lt;li&gt;Access permissions&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;CC File Structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Offset 0x0000 → CCLEN
Offset 0x0002 → Mapping Version
Offset 0x0003 → MLe
Offset 0x0005 → MLc
Offset 0x0007 → NDEF File Control TLV
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 6. TLV (Tag-Length-Value) Blocks
&lt;/h3&gt;

&lt;p&gt;TLV structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;T | L | V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tag = 04h → NDEF File Control TLV&lt;/li&gt;
&lt;li&gt;Length = 06h&lt;/li&gt;
&lt;li&gt;Value = 6 bytes describing NDEF file&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔵 7. NDEF File Structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----------------------+
| NLEN (2 bytes)       |
+----------------------+
| NDEF Message         |
+----------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NLEN indicates the size of the NDEF message.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔵 8. Complete APDU Flow (Reader → Android HCE)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. SELECT NDEF Application
   00 A4 04 00 07 D2 76 00 00 85 01 01 00
2. SELECT CC File
   00 A4 00 0C 02 E1 03
3. READ CC File
   00 B0 00 00 0F
4. SELECT NDEF File
   00 A4 00 0C 02 E1 04
5. READ NLEN
   00 B0 00 00 02
6. READ NDEF Message
   00 B0 00 00 &amp;lt;length&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 9. High-Level Architecture Diagram
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvrbynu2xhbt0zg2fssdk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvrbynu2xhbt0zg2fssdk.png" alt="HCE Architecture " width="581" height="706"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1fawy2s0nuj4p5txa1zi.png" alt="APDU Sequence" width="612" height="558"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🏁 Conclusion (Part 1)
&lt;/h3&gt;

&lt;p&gt;In this article, we covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ISO-DEP fundamentals&lt;/li&gt;
&lt;li&gt;APDU structure&lt;/li&gt;
&lt;li&gt;Type 4 Tag architecture&lt;/li&gt;
&lt;li&gt;CC file and TLV blocks&lt;/li&gt;
&lt;li&gt;NDEF storage model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 In Part 2, we’ll build a full Android HCE implementation with real Kotlin code and examine how to handle SELECT and READ commands in HostApduService.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Wrote This
&lt;/h2&gt;

&lt;p&gt;I wrote this article to provide a deeper technical explanation of Android HCE beyond surface-level tutorials. Understanding ISO-DEP and APDU at the protocol level is essential when building reliable NFC systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  💬 Let’s Discuss
&lt;/h2&gt;

&lt;p&gt;Are you currently building an Android HCE or NFC-based application?&lt;/p&gt;

&lt;p&gt;Do you have questions about ISO-DEP, APDU structure, or HostApduService implementation?&lt;/p&gt;

&lt;p&gt;Drop your questions in the comments — I’d be happy to help and may address them in Part 2.&lt;/p&gt;

</description>
      <category>android</category>
      <category>hce</category>
      <category>nfc</category>
      <category>kotlin</category>
    </item>
  </channel>
</rss>
