Menu

General Android Integration Guide


Part I: Including DyScan in your Android Studio Project

  • From the menubar, select File -> New -> New Module -> Import .jar/.aar and import dyscan.aar.

  • Then in your project’s build.gradle (the one under ‘app’) add the following:

  • dependencies {
        // Other dependencies are here
         implementation project(':dyscan')
         implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
         implementation 'com.android.support:support-v13:28.0.0'
    }
    
  • If you are using AndroidX, you will need implementation 'androidx.legacy:legacy-support-v13:1.0.0' as a dependency rather than com.android.support:support-v13:28.0.0'

  • In settings.gradle, add ‘:dyscan’ as part of the include

  • Clean build and build again

Part II: General Guide

First, we need to import two DyScan classes in your Activity that will launch DyScan:

import com.dyneti.android.dyscan.DyScanActivity;
import com.dyneti.android.dyscan.CreditCard;

This example assumes that you're going to launch the scanner from a button, and that you've set the button's onClick handler in the layout XML via android:onClick="onScanPress". (If not, the process is analogous, just use the code inside this function) Then, add the method as:


public void onScanPress(View v) {
    Intent scanIntent = new Intent(this, DyScanActivity.class);

    scanIntent.putExtra("api-key", "{api_key_string}");

    // MY_SCAN_REQUEST_CODE (e.g., 1) is arbitrary and is only used within this activity.
    startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}

(Make sure to replace “{api_key_string}” with your API key from Dyneti) and replace MY_SCAN_REQUEST_CODE with the arbitrary value. Next, we'll override onActivityResult() to get the scan result.


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);

   if (requestCode == 1) {
       if (data != null && data.hasExtra(DyScanActivity.EXTRA_SCAN_RESULT)) {
           CreditCard scanResult = data.getParcelableExtra(DyScanActivity.EXTRA_SCAN_RESULT);
           // Do stuff with results in scanResult 
       }
   }
  // Do stuff when no scan result is available.
}

The CreditCard class contains fields String cardNumber, int expiryMonth, int expiryYear, and boolean isFraud. Note that isFraud is currently always set to false.

Get Started