Class NFCTransfer

  • All Implemented Interfaces:
    com.scytales.mvalid.sdk.engagement.DeviceEngagementCapable , com.scytales.mvalid.sdk.engagement.DeviceEngagementSuspendable , com.scytales.mvalid.sdk.retrieval.TerminableTransfer , com.scytales.mvalid.sdk.retrieval.Timeoutable , com.scytales.mvalid.sdk.retrieval.Transfer , com.scytales.mvalid.sdk.retrieval.TransferProgressListenable , com.scytales.mvalid.sdk.retrieval.TransferReceiveDependent

    
    public final class NFCTransfer
     implements Transfer<D>, TerminableTransfer, TransferReceiveDependent, TransferProgressListenable, DeviceEngagementCapable, DeviceEngagementSuspendable, Timeoutable
                        

    Transfer implementation that enables device engagement and data transfer over NFC.

    IMPORTANT: NFC data transfer works only for NFC device engagement. If device engagement is accomplished using QR, data cannot be transferred using NFC.

    To enable NFCTransfer use enableDeviceEngagement method.

        public class SomeActivity extends 
    androidx.appcompat.app.AppCompatActivity
    implements DeviceEngagementCallback, TransferReceiveCallback, TransferProgressListener { private static final String TAG = "SomeActivity"; private Map<String, Map<String, Map<String, Boolean>>> docRequests = ... private NFCTransfer nfcTransfer; private SessionManager sessionManager; @Override protected void onCreate(@Nullable
    Bundle
    savedInstanceState) { super.onCreate(savedInstanceState); try { nfcTransfer = new NFCTransfer(); nfcTransfer.setTransferReceiveCallback(this); nfcTransfer.setProgressListener(this); } catch (SDKException e) {
    android.util.Log
    .e(TAG, e.getMessage(), e); } } @Override protected void onResume() { super.onResume(); if (null != nfcTransfer) { try { nfcTransfer.enableDeviceEngagement(this, this); } catch (SDKException e) {
    android.util.Log
    .e(TAG, e.getMessage(), e); } } } @Override protected void onPause() { super.onPause(); if (null != nfcTransfer) { nfcTransfer.disableDeviceEngagement(this); } } @Override public void onEngage(@NonNull Received<EngagementReceived> engagementReceived) { engagementReceived.run( failure -> {
    android.util.Log
    .e(TAG, failure.toString()); }, success -> { DeviceEngagement deviceEngagement = success.getDeviceEngagement(); Handover handover = success.getHandover(); try { sessionManager = new SessionManager(deviceEngagement, handover); byte[] requestBytes = sessionManager.createRequest(docRequests); nfcTransfer.send(requestBytes); } catch (SDKException e) {
    android.util.Log
    .e(TAG, e.getMessage(), e); } }); } @Override public void onProgressEvent(@NonNull TransferProgressEvent event) {
    android.util.Log
    .i(TAG, event.toString()); } @Override public void onReceive(@NonNull Received<TransferReceived> transferReceived) { transferReceived.run( failure -> {
    android.util.Log
    .e(TAG, failure.toString()); }, success -> { success.runForDevice(receivedBytes -> { try { com.scytales.mvalid.sdk.session.SessionData sessionData = sessionManager.decryptResponse(receivedBytes); // do stuff with decrypted } catch (SDKException e) { // handle decryption error } }); }); } }