How to Integrate the Kount SDK 4.1.x into an Android App

Note

Refer to How to Integrate the Kount SDK 4.2.x into an Android App for documentation on the latest SDK (4.2.x). Kount recommends upgrading to the latest SDK for optimal performance.

Provide native support for your Kount solution by integrating the Kount SDK into your Android application. This allows you to use Kount's service without having to create API calls. Software for this integration can be found in the GitHub repository.

Integrating the Kount SDK into the Android app

  1. Download the latest SDK from GitHub, and then extract the contents of the file.

  2. In Android Studio, copy the JAR file extracted from the SDK into the libs folder of your application (“Project Path”\app\libs).

  3. In the Project viewer, right-click the JAR file, and then click Add as library.

  4. In the Gradle file for your app, add the following:

        dependencies:dependencies {
        
              ...
        
              implementation 'com.google.android.instantapps:instantapps:1.1.0'
        
              implementation 'com.google.code.gson:gson:2.8.6'
        
              implementation group: 'com.android.volley', name: 'volley', version: '1.1.1'
        
              implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72'
        
        }
        

    Note

    The Kotlin library is only necessary if your application is written in Java. If your application uses Support libraries, then it must be migrated to Android X libraries. Refer to Migrate to AndroidX for steps on migrating to Android X libraries.

  5. To enable Location Collection support to detect devices in suspicious locations, add the following permissions to your application’s xml under the <manifest> tag:

        <uses-permission android:name="android.permission.INTERNET" />
        
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    Note

    While preferred, not all apps are approved in the app store to use the ACCESS_FINE_LOCATION. If your app has been rejected for having this permission, replace ACCESS_FINE_LOCATION (uses GPS) with ACCESS_COARSE_LOCATION (uses cellular triangulation).

  6. To enable Analytics Collection support, add the following to your application’s xml under the <application> tag:

        <application
        
        android:name="com.kount.api.analytics.AnalyticsApplication"
        
            ...>
        
            ...
        
        </application>
  7. In the main activity of your application, you need to initialize the collector and assign the <MERCHANT_ID> you received from Kount. Optionally, you can provide a session ID if you need to generate your own. If not, the SDK will generate one for you. You must send the session ID back to your servers in order to make calls to the Kount API (see the Kount API section below). Add the following initialization in your MainActivity:

    Kotlin:

        import com.kount.api.analytics.AnalyticsCollector
        
        …
        
        override fun onCreate(savedInstanceState: Bundle?) {
        
                    ...
        
                    // REQUIRED SECTION
        
                    setMerchantId(<MERCHANT_ID>)
        
                    // END REQUIRED SECTION
        
                    //This turns the alpha collections on(true)/off(false). It defaults to true
        
                    AnalyticsCollector.collectAnalytics(true)
        
                    //For production need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
        
                    AnalyticsCollector.setEnvironment(AnalyticsCollector.ENVIRONMENT_TEST)
        
                    // OPTIONAL SESSION_ID SECTION
        
                    val deviceSessionID = UUID.randomUUID().toString()
        
                    AnalyticsCollector.setSessionId(deviceSessionID)
        
                    // END OPTIONAL SESSION_ID SECTION
        
                    ...
        
        }

    Java:

        import com.kount.api.analytics.AnalyticsCollector;
        
        @Override
    
    protected void onCreate(Bundle savedInstanceState) {
        
              ...
        
              // REQUIRED SECTION
        
              AnalyticsCollector.setMerchantId(<MERCHANT_ID>);
        
              // END REQUIRED SECTION
        
              //This turns the alpha collections on(true)/off(false). It defaults to true
        
              AnalyticsCollector.collectAnalytics(true);
        
              //For production need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
        
              AnalyticsCollector.setEnvironment(AnalyticsCollector.ENVIRONMENT_TEST);
        
              // OPTIONAL SESSION_ID SECTION
        
              final String deviceSessionID = UUID.randomUUID().toString();
        
              AnalyticsCollector.setSessionId(deviceSessionID);
        
              // END OPTIONAL SESSION_ID SECTION
        
              ...
        
        }
  8. To support Location Collection in Android API 23 and above, add the following permissions to your main activity, onCreate method:

    Kotlin:

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        
              if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
        
                    requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 0)
        
              } else {
        
                    ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 0)
        
              }
        
        }

    Java:

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
              } else {
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
              }
        }
  9. To track login session data, add:

    Successful logins:

    Kotlin:

             trackLoginEvent(true)

    Java:

          AnalyticsCollector.trackLoginEvent(true);

    Unsuccessful logins:

    Kotlin:

    AnalyticsCollector.trackLoginEvent(false)

    Java:

    AnalyticsCollector.trackLoginEvent(false);
  10. Almost all Kount API calls require your Kount assigned merchantID and a sessionID. You must send the sessionID created earlier back to your servers. This can be done at any time prior to the Kount API calls being made (from your servers to ours). For example, if you are using Kount Control and plan to evaluate logins, you could include the sessionID along with the users login credentials to your servers. This sessionID is accessible as a global variable.

    This sessionID is accessible as a global variable:

    Kotlin:

        …
        
        val sessionId = AnalyticsCollector.getSessionId()
        
        // TODO add sessionId in posting to server here
        
        …

    Java:

        …
        
        String sessionId = AnalyticsCollector.getSessionId();
        
        // TODO add sessionId in posting to server here
        
        …
  11. Build and run.

    Note

    Refer to How to Integrate the Kount SDK 4.2.x into an Android App for documentation on the latest SDK (4.2.x). Kount recommends upgrading to the latest SDK for optimal performance.

    Provide native support for your Kount solution by integrating the Kount SDK into your Android application. This allows you to use Kount's service without having to create API calls. Software for this integration can be found in the GitHub repository.

Integrating the Kount SDK into the Android app

  1. Download the latest SDK from GitHub, and then extract the contents of the file.

  2. In Android Studio, copy the JAR file extracted from the SDK into the libs folder of your application (“Project Path”\app\libs).

  3. In the Project viewer, right-click the JAR, and then click Add as library.

  4. In the gradle file for your app, add the following

        dependencies:dependencies { 
        
              ...
        
              implementation 'com.google.android.instantapps:instantapps:1.1.0'
        
              implementation 'com.google.code.gson:gson:2.8.6'           
        
              implementation group: 'com.android.volley', name: 'volley', version: '1.1.1'
        
              implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72'
        
        }
        

    Note

    The Kotlin library is only necessary if your application is written in Java. If your application uses Support libraries, then it must be migrated to Android X libraries. Refer to Migrate to AndroidX for steps on migrating to Android X libraries.

  5. To enable Location Collection support to detect devices in suspicious locations, add the following permissions to your application’s xml under the <manifest> tag:

        <uses-permission android:name="android.permission.INTERNET" />
        
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  6. To enable Analytics Collection support, add the following to your application’s xml under the <application> tag:

        <application
        
        android:name="com.kount.api.analytics.AnalyticsApplication"
        
            ...>
        
            ...
        </application>
  7. In the main activity of your application, you will need to initialize the collector and assign the <MERCHANT_ID> you received from Kount. Optionally, you can provide a sessionID if you need to generate your own. If not, the SDK will generate one for you. You must send this sessionID back to your servers in order to make calls to the Kount API (see the Kount API section below). Add the following initialization in your MainActivity:

    Kotlin:

        import com.kount.api.analytics.AnalyticsCollector
        
        …
        
        override fun onCreate(savedInstanceState: Bundle?) {
        
                    ...
        
                    // REQUIRED SECTION
        
                    setMerchantId(<MERCHANT_ID>)
        
                    // END REQUIRED SECTION
        
                    //This turns the alpha collections on(true)/off(false). It defaults to true
        
                    AnalyticsCollector.collectAnalytics(true)
        
                    //For production need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
        
                    AnalyticsCollector.setEnvironment(AnalyticsCollector.ENVIRONMENT_TEST)
        
                    // OPTIONAL SESSION_ID SECTION
        
                    val deviceSessionID = UUID.randomUUID().toString()
        
                    AnalyticsCollector.setSessionId(deviceSessionID)
        
                    // END OPTIONAL SESSION_ID SECTION
        
                    ...
        
        }

    Java:

        import com.kount.api.analytics.AnalyticsCollector;
        
        @Override
        
        protected void onCreate(Bundle savedInstanceState) {
        
              ...
        
              // REQUIRED SECTION
        
              AnalyticsCollector.setMerchantId(<MERCHANT_ID>);
        
              // END REQUIRED SECTION
        
              //This turns the alpha collections on(true)/off(false). It defaults to true
        
              AnalyticsCollector.collectAnalytics(true);
        
              //For production need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
        
              AnalyticsCollector.setEnvironment(AnalyticsCollector.ENVIRONMENT_TEST);
        
              // OPTIONAL SESSION_ID SECTION
        
              final String deviceSessionID = UUID.randomUUID().toString();
        
              AnalyticsCollector.setSessionId(deviceSessionID);
        
              // END OPTIONAL SESSION_ID SECTION
        
              ...
        
        }
  8. To support Location Collection in Android API 23 and above, add the following permissions to your main activity, onCreate method:

    Kotlin:

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        
              if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
        
                    requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 0)
        
              } else {
        
                    ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 0)
        
              }
        
        }

    Java:

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
              } else {
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
              }
        }
  9. To track login session data, add:

    Successful logins:

    Kotlin:

         trackLoginEvent(true)

    Java:

          AnalyticsCollector.trackLoginEvent(true);

    Kotlin:

    AnalyticsCollector.trackLoginEvent(false)

    Java:

    AnalyticsCollector.trackLoginEvent(false);
  10. Almost all Kount API calls require your Kount assigned merchantID and a sessionID. You must send the sessionID created earlier back to your servers. This can be done at any time prior to the Kount API calls being made (from your servers to ours). For example, if you are using Kount Control and plan to evaluate logins, you could include the sessionID along with the users login credentials to your servers. This sessionID is accessible as a global variable.

    This sessionID is accessible as a global variable:

    Kotlin:

    …
    
    val sessionId =  AnalyticsCollector.getSessionId()
    
    // TODO add sessionId in posting to server here
    
    …

    Java:

    …
    
    String sessionId = AnalyticsCollector.getSessionId();
    
    // TODO add sessionId in posting to server here
    
    …
  11. Build and run.

Was this article helpful?
1 out of 1 found this helpful