Document Verification Android SDK
Android SDK
Installation
In order to install the Alloy SDK for Android, first add the maven repository to
your project's build.gradle
:
allprojects {
repositories {
// Your other repositories go here
maven { url "https://alloy-maven.z1digital.link" }
}
}
Then, add the SDK dependency to your app module's build.gradle
:
dependencies {
implementation "co.alloy:sdk:0.1.1"
}
Usage (in Kotlin)
Launching Alloy
package com.example
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import co.alloy.sdk.Alloy
import co.alloy.sdk.AlloyResult
import co.alloy.sdk.EvaluationData
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
private lateinit var alloy: Alloy
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
alloy = Alloy.init(
key = "xyz",
documentTypes = listOf(
listOf(
DocumentType.LICENSE,
DocumentType.PASSPORT,
),
),
selfieEnabled = true,
validationPreChecks = false,
evaluationData = EvaluationData(
nameFirst = "Antonio2",
nameLast = "Random"
),
journeyToken = "J-x",
journeyApplicationToken = "JA-x",
)
button.setOnClickListener {
alloy.open(this, ::onAlloyResult)
}
}
private fun onAlloyResult(result: AlloyResult) {
// Handle the result
}
}
Handling the result
private fun onAlloyResult(result: AlloyResult) {
val msg = when (result) {
is AlloyResult.Finished -> {
Log.i("Alloy", "Front document token = ${result.documentTokenBack}")
Log.i("Alloy", "Back document token = ${result.documentTokenFront}")
Log.i("Alloy", "Evaluation token = ${result.evaluationToken}")
Log.i("Alloy", "Entity token = ${result.entityToken}")
when (result.outcome) {
AlloyOutcome.APPROVED -> "The ID was approved!"
AlloyOutcome.DENIED -> "The ID was denied!"
AlloyOutcome.MANUAL_REVIEW -> "The ID will be manually verified"
}
}
is AlloyResult.Cancelled -> "Verification cancelled by the user"
is AlloyResult.UnexpectedError -> {
Log.e("Alloy SDK", "Alloy SDK unexpected error", result.error)
"An unexpected error occurred!"
}
}
Snackbar.make(constraintLayout, msg, Snackbar.LENGTH_LONG)
.show()
}
Customizing options or passing more data
Alloy.init(
key = "028d85e0-aa24-4ca1-99f2-90e3ee3f4e6b",
externalEntityId = "my-external-entity-id",
entityToken = "my-entity-token",
production = true,
maxEvaluationAttempts = 3,
evaluationData = EvaluationData(
nameFirst = "John",
nameLast = "Doe",
addressLine1 = "123 Fake Street",
addressLine2 = "1st 2nd",
addressCity = "New York",
addressPostalCode = "12345",
addressCountryCode = "US",
birthDate = Calendar.getInstance().apply {
set(Calendar.DAY_OF_MONTH, 1)
set(Calendar.MONTH, 1)
set(Calendar.YEAR, 2000)
}.time
)
)
Usage (in Java)
Launching Alloy
public class MainActivity extends AppCompatActivity {
private Alloy alloy;
@Override
public void onCreate(
@Nullable Bundle savedInstanceState,
@Nullable PersistableBundle persistentState
) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_alloy);
alloy = new Alloy.Builder(
"your-alloy-key"
)
.withEvaluationData(
new EvaluationData.Builder()
.withNameFirst("John")
.withNameLast("Doe")
.build()
)
.init();
findViewById(R.id.button).setOnClickListener((view) ->
alloy.open(this, this::onAlloyResult)
);
}
private void onAlloyResult(AlloyResult result) {
// TODO
}
}
Handling the result
private void onAlloyResult(AlloyResult result) {
String msg = "";
if (result instanceof AlloyResult.Finished) {
AlloyResult.Finished finishedResult = (AlloyResult.Finished) result;
Log.i("Alloy", "Front document token = " + finishedResult.getDocumentTokenFront());
Log.i("Alloy", "Back document token = " + finishedResult.getDocumentTokenBack());
Log.i("Alloy", "Evaluation token = " + finishedResult.getEvaluationToken());
Log.i("Alloy", "Entity token = " + finishedResult.getEntityToken());
switch (finishedResult.getOutcome()) {
case APPROVED:
msg = "The ID was approved!";
break;
case DENIED:
msg = "The ID was denied!";
break;
case MANUAL_REVIEW:
msg = "The ID will be manually verified";
break;
}
}
if (result instanceof AlloyResult.Cancelled) {
msg = "Verification cancelled by the user";
}
if (result instanceof AlloyResult.UnexpectedError) {
AlloyResult.UnexpectedError errorResult = (AlloyResult.UnexpectedError) result;
Log.e("Alloy", "Alloy SDK unexpected error", errorResult.getError());
msg = "An unexpected error occurred!";
}
Snackbar.make(findViewById(R.id.constraintLayout), msg, Snackbar.LENGTH_LONG)
.show();
}
Customizing options or passing more data
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.YEAR, 2000);
Date birthDate = calendar.getTime();
alloy = new Alloy.Builder(
"028d85e0-aa24-4ca1-99f2-90e3ee3f4e6b"
)
.withExternalEntityId("my-external-entity-id")
.withEntityToken("my-entity-token")
.withMaxEvaluationAttempts(3)
.inProduction()
.withEvaluationData(
new EvaluationData.Builder()
.withNameFirst("John")
.withNameLast("Doe")
.withAddressLine1("123 Fake Street")
.withAddressLine2("1st 2nd")
.withAddressCity("New York")
.withAddressPostalCode("12345")
.withAddressCountryCode("US")
.withBirthDate(birthDate)
.build()
)
.init();
Updated 2 months ago