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
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(@Nullableandroidx.appcompat.app.AppCompatActivity
savedInstanceState) { super.onCreate(savedInstanceState); try { nfcTransfer = new NFCTransfer(); nfcTransfer.setTransferReceiveCallback(this); nfcTransfer.setProgressListener(this); } catch (SDKException e) {Bundle
.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 } }); }); } }android.util.Log
-
-
Constructor Summary
Constructors Constructor Description NFCTransfer()
-
Method Summary
Modifier and Type Method Description NFCTransfer
enableDeviceEngagement(@NonNull() ComponentActivity activity, @NonNull() DeviceEngagementCallback callback)
Enables deviceEngagement detection. NFCTransfer
suspendDeviceEngagement()
Suspend device engagement. NFCTransfer
resumeDeviceEngagement()
Resume device engagement. NFCTransfer
unsetTransferProgressListener()
Unset transfer progress listener transfer progress listenable. NFCTransfer
setTransferReceiveCallback(@NonNull() TransferReceiveCallback callback)
Sets transfer receive callback. void
send(@NonNull() Request request)
Send. NFCTransfer
setTimeout(int timeoutInMillis)
Sets timeout. void
sendTermination()
Send termination. NFCTransfer
setTransferProgressListener(@NonNull() TransferProgressListener transferProgressListener)
Sets transfer progress listener. -
-
Method Detail
-
enableDeviceEngagement
@MainThread() NFCTransfer enableDeviceEngagement(@NonNull() ComponentActivity activity, @NonNull() DeviceEngagementCallback callback)
Enables deviceEngagement detection.
- Parameters:
activity
- the activitycallback
- the callback
-
suspendDeviceEngagement
NFCTransfer suspendDeviceEngagement()
Suspend device engagement.
-
resumeDeviceEngagement
NFCTransfer resumeDeviceEngagement()
Resume device engagement.
-
unsetTransferProgressListener
@NonNull() NFCTransfer unsetTransferProgressListener()
Unset transfer progress listener transfer progress listenable.
-
setTransferReceiveCallback
@NonNull() NFCTransfer setTransferReceiveCallback(@NonNull() TransferReceiveCallback callback)
Sets transfer receive callback.
- Parameters:
callback
- the callback
-
setTimeout
NFCTransfer setTimeout(int timeoutInMillis)
Sets timeout.
- Parameters:
timeoutInMillis
- the timeout in millis
-
sendTermination
void sendTermination()
Send termination.
-
setTransferProgressListener
@NonNull() NFCTransfer setTransferProgressListener(@NonNull() TransferProgressListener transferProgressListener)
Sets transfer progress listener.
-
-
-
-