Skip to main content

Android NFC Integration Guide

Add the Dyneti Maven repository to your project

In your project-level build.gradle add the Dyneti Maven repository (credentials provided during integration):

allprojects {
repositories {
// Other repositories are here
maven {
credentials {
username = "nexusUsername"
password = "nexusPassword"
}
url "https://nexus.dyneti.com/repository/maven-releases/"
authentication {
basic(BasicAuthentication)
}
}
}
}
info

If you would rather integrate without using our Nexus repository, see Manually Importing the Library.

Add the Dyneti and NFC library dependencies

Include both the DyScan SDK and the NFC SDK. Both should be the same version, e.g. 1.7.18 or greater.

implementation("com.dyneti.android.dyscan:dyscan-fraud:${dyscanVersion}")
implementation("com.dyneti.android.nfc:dyneti-nfc:${dyscanVersion}")

Initialize DyScan

In your Application class add the following line to initialize DyScan.

public class DyScanApplication extends Application {

//...

@Override
public void onCreate() {
super.onCreate();
//...
DyScan.init(this, "{YOUR_API_KEY}");
//...
}
}

Check if the device supports NFC scanning

You can use the method DyScan.hasNfcFeature() to confirm that the device your app is running on is able to scan cards using NFC. It will return true if the device is supported and dynetiNFC has loaded. It will return false if the device is not supported or the NFC SDK could not be found.

Enable and Disable NFC scanning in your activity

In the activity you would like to perform the scan, enable the scanner during your onResume method and disable the scanner in your onPause method.

    override fun onResume() {
super.onResume()
if (DyScan.hasNfcFeature()) {
DyScan.dynetiNFC.enableScanning(this);
}
}

override fun onPause() {
if (DyScan.hasNfcFeature()) {
DyScan.dynetiNFC.disableScanning(this);
}
super.onPause()
}

Read the result of the NFC Scan

In your activity, listen for the result intent using the onNewIntent method:

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
if (DyScan.hasNfcFeature()) {
DyScan.dynetiNFC.handleIntent(
intent,
{ result: com.dyneti.shared_interfaces.DynetiNFCCard ->
val card = result
runOnUiThread {
findViewById<TextView>(R.id.cardNumber).setText(card.cardNumber);
findViewById<TextView>(R.id.expirationMonth).setText(card.expirationMonth);
findViewById<TextView>(R.id.expirationYear).setText(card.expirationYear);
findViewById<TextView>(R.id.errorText).setText("")
}
},
{ error: String? ->
Log.d("NFC", "error: $error")
runOnUiThread {
findViewById<TextView>(R.id.errorText).setText(error)
}
})
}
}