Android Question Host Card Emulator Library

mike1967

Active Member
Licensed User
Longtime User
Hello, regarding to Host Card Emulation library, can someone test this one attached ? I have ony one device with NFC capability . The library is realized thanks to AI , i hope working.
Code:
*** CONFIGURAZIONE MANIFEST B4A ***
(Copia questo nel Manifest Editor di B4A)

AddPermission(android.permission.NFC)
AddFeature(android.hardware.nfc.hce)

AddServiceText(HceManager.HceService,
<intent-filter>
    <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
</intent-filter>
<meta-data android:name="android.nfc.cardemulation.host_apdu_service"
    android:resource="@xml/apduservice"/>)

CreateResource(xml, apduservice.xml,
<host-apdu-service xmlns:android="http://android.com"
    android:description="B4A HCE Emulator"
    android:requireDeviceUnlock="false">
    <aid-group android:description="NFC Forum Type 4" android:category="other">
        <aid-filter android:name="D2760000850101"/>
    </aid-group>
</host-apdu-service>)

*** CODICE ESEMPIO B4A ***

Sub Process_Globals
    Private nfc As HceManager
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        nfc.Initialize(Me, "nfc")
    End If
    nfc.SetTagText("Mio Messaggio NFC")
End Sub

Sub nfc_OnReaderConnected
    Log("Un lettore NFC ha toccato il telefono!")
End Sub

Sub nfc_OnMessageReceived(Status As String)
    Log("Stato: " & Status)
End Sub
 

Attachments

  • hce.zip
    2.7 KB · Views: 3
  • B4A_HCE_SRC_SLC.zip
    6 KB · Views: 2

mike1967

Active Member
Licensed User
Longtime User
updated:
*** CONFIGURAZIONE MANIFEST B4A ***
(Copia questo nel Manifest Editor di B4A)

AddPermission(android.permission.NFC)

' NOTA: AddFeature non esiste in B4A. <uses-feature> non e' necessaria per il funzionamento
' dell'HCE - serve solo come filtro Play Store. Si puo' omettere senza problemi.

' NOTA: AddServiceText e' per servizi B4A-compilati.
' Per una libreria Java esterna usare AddManifestText con il percorso completo della classe.
AddManifestText(
<service
    android:name="com.hce.wrapper.HceManager$HceService"
    android:exported="true"
    android:permission="android.permission.BIND_NFC_SERVICE">
    <intent-filter>
        <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
    </intent-filter>
    <meta-data android:name="android.nfc.cardemulation.host_apdu_service"
        android:resource="@xml/apduservice"/>
</service>)

' NOTA: namespace corretto e' schemas.android.com, non android.com
CreateResource(xml, apduservice.xml,
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="B4A HCE Emulator"
    android:requireDeviceUnlock="false">
    <aid-group android:description="NFC Forum Type 4" android:category="other">
        <aid-filter android:name="D2760000850101"/>
    </aid-group>
</host-apdu-service>)

*** CODICE ESEMPIO B4A ***

Sub Process_Globals
    Private nfc As HceManager
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        nfc.Initialize(Me, "nfc")
    End If
    nfc.SetTagText("Mio Messaggio NFC")
End Sub

Sub nfc_OnReaderConnected
    Log("Un lettore NFC ha toccato il telefono!")
End Sub

Sub nfc_OnMessageReceived(Status As String)
    Log("Stato: " & Status)
End Sub
 

Attachments

  • hce.zip
    2.9 KB · Views: 2
  • B4A_HCE_SRC_SLC_Updated.zip
    6.8 KB · Views: 3
Upvote 0

teddybear

Well-Known Member
Licensed User
You'd best upload a small project. are you sure the parameters of the nfc.Initialize are correct?
 
Upvote 0

mike1967

Active Member
Licensed User
Longtime User
Manifest Updated:
AddPermission(android.permission.NFC)

AddApplicationText(
<service
    android:name="com.hce.wrapper.HceManager$HceService"
    android:exported="true"
    android:permission="android.permission.BIND_NFC_SERVICE">
    <intent-filter>
        <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
    </intent-filter>
    <meta-data android:name="android.nfc.cardemulation.host_apdu_service"
        android:resource="@xml/apduservice"/>
</service>)

CreateResource(xml, apduservice.xml,
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/hce_description"
    android:requireDeviceUnlock="false">
    <aid-group android:description="@string/hce_aid_description" android:category="other">
        <aid-filter android:name="D2760000850101"/>
    </aid-group>
</host-apdu-service>)

CreateResource(values, strings_hce.xml,
<resources>
    <string name="hce_description">B4A HCE Emulator</string>
    <string name="hce_aid_description">NFC Forum Type 4</string>
</resources>)

Seems to compile ok
 

Attachments

  • Backup hce 2026-04-29 17.57.zip
    9.6 KB · Views: 1
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…