Using the Android SDK

This topic provides detailed information on how to use the Android SDK.

Installation

Follow these steps to install Android SDK:

  1. Place the "netspendsdk-release.aar" file that you received into your Android app module's libs directory.
  2. Add implementation files ('libs/netspendsdk-release.aar') to your app module's dependencies in build.gradle as shown in the sample code below:
dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    // Note: Add the following as dependencies. Gradle does not automatically 
    // include transitive dependencies of `.aar` files when used outside of a 
    // maven registry.
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'org.bitbucket.b_c:jose4j:0.6.4'
    implementation 'de.adorsys.android:securestoragelibrary:1.2.2'
    // NetspendSDK framework
    implementation files('libs/netspendsdk-release.aar')
}

This framework is built with Kotlin, but it can be used with Java as well. The Android minSdkVersion is set to 21, which equates to Android 5.0 (Lollipop).

Initialization

When your application starts, make sure to initialize the Netspend SDK. This will allow for the downloading and caching of external assets without any noticeable delays when launching micro-apps. As part of the initialization process, ensure to set up the theme and branding information, to facilitate a seamless appearance of micro-apps within your mobile application.

Global Initialization

You need the global single initialization once per app life-cycle, typically in onCreate of your MainActivity. to initialize, you need, sdkID, iovation_token. You also need to configure theme and branding details.

import com.netspend.sdk.NetspendSdk
NetspendSdk.shared.initialize(
  // The SDK ID for your integration, given from Netspend. 
  // This is not a secret value.
  sdkID,
  // The theme configuration
  theme,
  // Branding configuration, see each micro-app for details
  branding, 
  // Iovation Token using the Fraudforce lib
  iovation_token
)

Extend the NetspendSdkActivity Base Class

To use this SDK, extend the NetspendSdkActivity Android Activity Class. You must implement the following methods to receive notifications about the Netspend User Activity.

In the State Change blocks to close your activity when key user events occur, you will call the standard finish() class.

import com.netspend.sdk.NetspendSdkActivity
import com.netspend.sdk.NetspendSdkPurposeState
class MyNetspendActivity : NetspendSdkActivity() {
  override fun onNetspendSdkEvent(event: String, data: Map<String, Any>)  {
      System.out.println("Received event from current NetspendSdk purpose: " + event)
      System.out.println(data)
  }
  override fun onNetspendSdkStateChange(state: NetspendSdkPurposeState, data: Map<String, Any>){
    when(state) {
      NetspendSdkPurposeState.STARTED ->
        System.out.println("[NetspendSDK] Purpose $purposeName has been started!")
      NetspendSdkPurposeState.CANCELLED -> {
        System.out.println("[NetspendSDK] Purpose $purposeName was requested to be canceled by the user!")
        finish()
      }
      NetspendSdkPurposeState.ERROR -> {
        System.out.println("[NetspendSDK] Purpose $purposeName encountered an error!")
        System.out.println(data)
        finish()
      }

      NetspendSdkPurposeState.SUCCESS -> {
        System.out.println("[NetspendSDK] Purpose $purposeName was successful!")
        System.out.println(data)
        finish()
      }
    }
  }
}

See Customization for detailed information on theme and branding.