Read and write a PC/SC smart card in an Android App with Delphi Rio 10.3.1 [on hold]

  

I’m trying to read and write the content of a PC/SC smart card using Delphi 10.3.1 without sucess on Android Apps. I found some related topics, but they make reference to NFC reading and writing and I need to do it using a Gemalto IDBridge CT-30 card reader connected through the mini-USB port.

To ensure that it is possible, I have installed an ATR reader App on my cell phone and it works fine. Till now I was unable to connect, read and write the smart card data through the card reader.

I found this code in some of my searches, that can be seen in this answer too:

unit Androidapi.JNI.NfcAdapter;

// JNI NFC import demo
// Note – REQUIRES – PROJECT OPTIONS – USES PERMISSIONS – NFC

interface

uses
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.GraphicsContentViewText,
FMX.Helpers.Android,
SysUtils,
Classes;

type
/////////////////////////// NfcAdapter /////////////////////////////////
JNfcManager = interface;
JNfcAdapter = interface;

JNfcAdapterClass = interface(JObjectClass)
[‘{634258AC-7931-4E38-97E6-48DBF688A288}’]
{Property methods}
function _ACTION_TAG_DISCOVERED: JString; cdecl;
function _EXTRA_ID: JString; cdecl;
function _EXTRA_NDEF_MESSAGES: JString; cdecl;
function _EXTRA_TAG: JString; cdecl;
{Properties}
property ACTION_TAG_DISCOVERED: JString read _ACTION_TAG_DISCOVERED;
property EXTRA_ID: JString read _EXTRA_ID;
property EXTRA_NDEF_MESSAGES: JString read _EXTRA_NDEF_MESSAGES;
property EXTRA_TAG: JString read _EXTRA_TAG;
end;

[JavaSignature(‘android/nfc/NfcAdapter’)]
JNfcAdapter = interface(JObject)
[‘{364D8F3F-23AE-4C28-A261-E30C0893B24C}’]
//Return true if this NFC Adapter has any features enabled
function isEnabled: Boolean; cdecl;
end;

TJNfcAdapter = class(TJavaGenericImport<JNfcAdapterClass, JNfcAdapter>) end;

/////////////////////////// NfcManager /////////////////////////////////

JNfcManagerClass = interface(JObjectClass)
[‘{812481E1-F491-47D2-AC1F-4C5AB509532B}’]
end;

[JavaSignature(‘android/nfc/NfcManager’)]
JNfcManager = interface(JObject)
[‘{04B707EC-966A-4E4F-85DC-F003B7C9ACE3}’]
{Methods}
function getDefaultAdapter: JNfcAdapter; cdecl;
end;

TJNfcManager = class(TJavaGenericImport<JNfcManagerClass, JNfcManager>) end;

function HasNfc: Boolean;
function IsNfcEnabled: Boolean;

implementation

function GetNfcManager: JNfcManager;
var
ConnectivityServiceNative: JObject;
begin
ConnectivityServiceNative := SharedActivityContext.getSystemService(TJContext.JavaClass.NFC_SERVICE);
if not Assigned(ConnectivityServiceNative) then
raise Exception.Create(‘Could not locate Nfc Service’);
Result := TJNfcManager.Wrap((ConnectivityServiceNative as ILocalObject).GetObjectID);
if not Assigned(Result) then
raise Exception.Create(‘Could not access Nfc Manager’);
end;

function HasNfc: Boolean;
var
NfcManager: JNfcManager;
NfcAdapter: JNfcAdapter;
begin
NfcManager := GetNfcManager;
NfcAdapter := NfcManager.getDefaultAdapter;
Result := Assigned(NfcAdapter);
end;

function IsNfcEnabled: Boolean;
var
NfcManager: JNfcManager;
NfcAdapter: JNfcAdapter;
begin
NfcManager := GetNfcManager;
NfcAdapter := NfcManager.getDefaultAdapter;
Result := Assigned(NfcAdapter)and NfcAdapter.isEnabled;
end;

end.

This code only provides NFC connectivity but the target devices doesn’t have NFC sensors, so I can’t use it.

Dave Nottage sent this link, but the headers found can’t provide a usefull connection with the PC/SC card reader.

The manufacturer doesn’t have any SDK for Android development since they stablish its use for PC only (Linux, Windows and MacOS).

Facing that, till now, I was unable to successfully connect and read/write the smart card on Android.

Comments are closed.