Device Connect Android SDK Integration

Simple and fast integration of Device Connect Android SDK

Srikar Reddy
FinBox

--

Device Connect Android SDK is used to collect anonymized non-personal data from the user's device upon explicit consent. The rich data collected is used to understand the user's credit profile which helps the clients make decisions on lending amounts and tenures.

You should have received the necessary secret keys from the business team which are essential to start the integration of the SDK. If not then request the details before continuing.

Add the shared AWS access and secret keys to local.properties to make sure the keys aren’t leaked through Git commits.

Open the project level build.gradle file and navigate to the repositories section inside allprojects block where we need to add the maven repository URL and the AWS keys.

maven {
url gradleProperties.getProperty('AWS_REPO_URL')
credentials(AwsCredentials) {
accessKey = gradleProperties.getProperty('AWS_ACCESS_KEY')
secretKey = gradleProperties.getProperty('AWS_SECRET_KEY')
}
}

The variable named gradleProperties is defined outside the allprojects block. Create an instance of Properties and pass the local.properties file as an InputStream to the load function.

Properties gradleProperties = new Properties()
gradleProperties.load(new FileInputStream(project.rootProject.file('local.properties')))

In case you are using Gradle’s Kotlin DSL, the syntax will change a bit.

maven {
setUrl(gradleProperties.getProperty('AWS_REPO_URL'))
credentials(AwsCredentials::class) {
accessKey = gradleProperties.getProperty("AWS_ACCESS_KEY")
secretKey = gradleProperties.getProperty("AWS_SECRET_KEY")
}
}

Similarly, create an instance and load the local.properties file using Kotlin.

val gradleProperties = Properties()
gradleProperties.load(FileInputStream(project.rootProject.file("local.properties")))

Add the dependency to the module level build.gradle file and trigger the Gradle syncs to download the Device Connect Android library .aar file. Set transitive to true so that the transitive dependencies are downloaded.

implementation('in.finbox:mobileriskmanager:2.8:parent-release@aar') {
transitive = true
}

In case of the module level build.gradle.kts file, try

implementation("in.finbox:mobileriskmanager:2.8:parent-release@aar") {
isTransitive = true
}

If the dependencies fail to sync,

  1. Check whether available access keys and secret keys are the latest.
  2. Disable offline mode option in Android Studio if enabled.
  3. Check if your company’s network isn’t blocking the outgoing requests.
  4. Check the internet connectivity.

If the above solutions fail to resolve the issue, reach out to us.

The permissions are automatically added to your app’s AndroidManifest.xml file if Manifest Merger is enabled. In case if the Manifest Merger is disabled, add the supported permissions manually. Request the necessary dangerous permissions during Runtime.

The below chart shows a simple workflow that is followed by the clients while integrating the Device Connect Android SDK.

Typical Integration Flow

Once the permissions are granted, call the createUser method with API key, customer id along with the callbacks as parameters to create the user.

The customer id is a unique identifier generated by the client and is used to request the processed data.

Read the API key from the C++ layer to make it harder for hackers to reverse engineer. If your company uses another secure way, continue to use it. Just make sure that you don’t store the API key as an unmasked string as the bills may get inflated in case of a leak.

suspend fun createUser(apiKey: String, customerId: String) =
suspendCoroutine<Boolean> {
FinBox.createUser(apiKey, customerId,
object : FinBox.FinBoxAuthCallback {
override fun onSuccess(accessToken: String) {
// Authentication success
startPeriodicSync()
// Resume the Coroutine
it.resume(true)
}

override fun onError(@FinBoxErrorCode errorCode: Int) {
// Authentication failed
it.resume(false)
}
})
}

onSuccess callback is returned when the user is successfully created otherwise onError callback is returned. The onError callback returns Error codes specified in the documentation.

If the user is created successfully, start the periodic syncs.

private fun startPeriodicSync() {
val finBox = FinBox()
finBox.startPeriodicSync()
}

The startPeriodicSync method will start sending the data immediately to our servers and also sets periodic sync frequency of 8 hours. This frequency can be changed by setSyncFrequency method. Call it before you start the periodic syncs.

finBox.setSyncFrequency(TimeUnit.HOURS.toSeconds(hours))

When your company decides to stop sending/sharing the data with us you can call the stopPeriodicSync method.

private fun stopPeriodicSync() {
val finBox = FinBox()
finBox.stopPeriodicSync()
}

FinBox works with banks & NBFCs to digitize their customer journeys & to help them underwrite NTC customers using alternative data from the smartphone. To figure out the creditworthiness of your first time borrowers, get in touch.

We are hiring!!! If you want to be part of the team building the future architecture of financial services, reach out with your accomplishments at srikar@finbox.in OR tech@finbox.in

--

--