Overview
The KountSDK class is the primary interface for integrating Kount device data collection into your Android application. It provides methods to configure the SDK, initiate data collection, and retrieve session information.
Package
Usage in Kotlin
Access the singleton instance directly:
KountSDK. setMerchantId ( "999999" )
KountSDK. collectForSession (context, successCallback, failureCallback)
Usage in Java
Access through the INSTANCE property:
KountSDK . INSTANCE . setMerchantId ( "999999" );
KountSDK . INSTANCE . collectForSession (context, successCallback, failureCallback);
Configuration Methods
setMerchantId()
Sets the merchant identifier for the SDK.
KountSDK. setMerchantId (merchantId: String )
Your unique Kount merchant ID (6-digit number). Contact Kount support to obtain your merchant ID.
Example:
KountSDK. setMerchantId ( "999999" )
KountSDK . INSTANCE . setMerchantId ( "999999" );
setEnvironment()
Configures the SDK to connect to either the test or production environment.
KountSDK. setEnvironment (environment: Int )
The environment constant. Use ENVIRONMENT_TEST for testing or ENVIRONMENT_PRODUCTION for live transactions.
Example:
KountSDK. setEnvironment (KountSDK.ENVIRONMENT_TEST)
KountSDK . INSTANCE . setEnvironment ( KountSDK . ENVIRONMENT_TEST );
Always use ENVIRONMENT_TEST during development and testing. Only switch to ENVIRONMENT_PRODUCTION when deploying to production.
setCollectAnalytics()
Enables or disables analytics data collection.
KountSDK. setCollectAnalytics (enabled: Boolean )
Set to true to enable analytics collection, or false to disable. Defaults to true.
Example:
KountSDK. setCollectAnalytics ( true )
KountSDK . INSTANCE . setCollectAnalytics ( true );
Collection Methods
collectForSession()
Initiates device data collection for the current session.
KountSDK. collectForSession (
context: Context ,
onSuccess: ( String ) -> Unit ,
onFailure: ( String , String ) -> Unit
)
The Android Context (typically an Activity or Application context).
Success callback that receives the session ID when collection completes successfully.
onFailure
(String, String) -> Unit
required
Failure callback that receives the session ID and error message if collection fails.
Kotlin Example:
KountSDK. collectForSession (
this ,
{ sessionId ->
Log. d ( "Kount" , "Success: $sessionId " )
// Send sessionId to your backend
},
{ sessionId, error ->
Log. e ( "Kount" , "Failed: $error " )
// Handle error
}
)
Java Example:
KountSDK . INSTANCE . collectForSession (
this ,
(sessionId) -> {
Log . d ( "Kount" , "Success: " + sessionId);
// Send sessionId to your backend
return null ;
},
(sessionId, error) -> {
Log . e ( "Kount" , "Failed: " + error);
// Handle error
return null ;
}
);
This method is asynchronous. The callbacks will be invoked when collection completes or fails.
Query Methods
getSessionId()
Retrieves the current session ID.
KountSDK. getSessionId (): String
The current session identifier. Returns an empty string if collection hasn’t started.
Example:
val sessionId = KountSDK. getSessionId ()
println ( "Session ID: $sessionId " )
String sessionId = KountSDK . INSTANCE . getSessionId ();
Log . d ( "Kount" , "Session ID: " + sessionId);
getCollectionStatus()
Retrieves the current status of the data collection process.
KountSDK. getCollectionStatus (): String
The collection status as a string. Possible values: “COMPLETED”, “FAILED”, “IN_PROGRESS”.
Example:
val status = KountSDK. getCollectionStatus ()
when (status) {
CollectionStatus.COMPLETED. toString () -> println ( "Collection complete" )
CollectionStatus.FAILED. toString () -> println ( "Collection failed" )
CollectionStatus.IN_PROGRESS. toString () -> println ( "Collection in progress" )
}
String status = KountSDK . INSTANCE . getCollectionStatus ();
if ( status . equals ( CollectionStatus . COMPLETED . toString ())) {
Log . d ( "Kount" , "Collection complete" );
}
Constants
REQUEST_PERMISSION_LOCATION
Request code for location permission requests.
const val REQUEST_PERMISSION_LOCATION: Int
Use this constant when requesting location permissions to ensure the SDK can collect location data:
Example:
ActivityCompat. requestPermissions (
activity,
arrayOf (Manifest.permission.ACCESS_FINE_LOCATION),
KountSDK.REQUEST_PERMISSION_LOCATION
)
override fun onRequestPermissionsResult (
requestCode: Int ,
permissions: Array < out String >,
grantResults: IntArray
) {
if (requestCode == KountSDK.REQUEST_PERMISSION_LOCATION) {
// Handle permission result
KountSDK. collectForSession ( this , onSuccess, onFailure)
}
super . onRequestPermissionsResult (requestCode, permissions, grantResults)
}
ActivityCompat . requestPermissions (
activity,
new String []{ Manifest . permission . ACCESS_FINE_LOCATION },
KountSDK . REQUEST_PERMISSION_LOCATION
);
@ Override
public void onRequestPermissionsResult ( int requestCode, String [] permissions, int [] grantResults) {
if (requestCode == KountSDK . REQUEST_PERMISSION_LOCATION ) {
// Handle permission result
KountSDK . INSTANCE . collectForSession ( this , onSuccess, onFailure);
}
super . onRequestPermissionsResult (requestCode, permissions, grantResults);
}
ENVIRONMENT_TEST
Environment constant for the test/sandbox environment.
const val ENVIRONMENT_TEST: Int
See Environment Constants for details.
ENVIRONMENT_PRODUCTION
Environment constant for the production environment.
const val ENVIRONMENT_PRODUCTION: Int
See Environment Constants for details.
Best Practices
Configure the SDK (merchant ID, environment) in your Application class or early in your app lifecycle before initiating collection. class MyApplication : Application () {
override fun onCreate () {
super . onCreate ()
KountSDK. setMerchantId ( "999999" )
KountSDK. setEnvironment (KountSDK.ENVIRONMENT_TEST)
KountSDK. setCollectAnalytics ( true )
}
}
Request Location Permissions
For optimal data collection, request location permissions before calling collectForSession(). if (ContextCompat. checkSelfPermission ( this , Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat. requestPermissions (
this ,
arrayOf (Manifest.permission.ACCESS_FINE_LOCATION),
KountSDK.REQUEST_PERMISSION_LOCATION
)
} else {
KountSDK. collectForSession ( this , onSuccess, onFailure)
}
Always send the session ID to your backend after successful collection. Your backend should include this ID when making fraud evaluation requests to Kount. KountSDK. collectForSession (
this ,
{ sessionId ->
// Send to backend
apiService. submitTransaction (sessionId, orderData)
},
{ sessionId, error ->
// Log error and potentially retry
Log. e ( "Kount" , "Collection failed: $error " )
}
)
Monitor the collection status to provide feedback to users or handle edge cases. val status = KountSDK. getCollectionStatus ()
when (status) {
CollectionStatus.IN_PROGRESS. toString () -> showLoading ()
CollectionStatus.COMPLETED. toString () -> enableCheckout ()
CollectionStatus.FAILED. toString () -> handleFailure ()
}