Search
⌃K

Android

This guide helps you to integrate the Passbase SDK into your native Android project

General

Before you start integrating Passbase, we suggest you read first our Overview & Integration Guide on how to integrate Passbase in your system and complete the initial setup steps.
You can either follow the integration guide or watch the integration tutorial that shows the same steps. Please be aware that some property or function names might have slightly changed with newer versions. Make sure to compare your implementation with the latest code snippets here in the documentation.

1. Install the Gradle Plugin

To install the Passbase Android SDK, add the following to your project’s build.gradle file:
  1. 1.
    Please use minSdkVersion 21 in your build.gradle (Module:app)
  2. 2.
    Add maven {url 'https://button.passbase.com/__android'} to your repositories part
  3. 3.
    Finally, add implementation 'com.passbase:passbase_sdk:2.13.6' to your dependencies.
A complete build.gradlefile should look similar to the example below. Now sync your build.gradle file to install the SDK.
android {
// 1. Ensure you have hat least minSdkVersion 21
compileSdkVersion 30
defaultConfig {
applicationId "com.passbase.passbaseexample"
mindSdkVersion 21
compileSdkVersion 32
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
}
repositories {
// 2. Add line here
maven { url 'https://button.passbase.com/__android' }
}
dependencies {
...
// 3. Add line here
implementation 'com.passbase:passbase_sdk:2.13.6'
}
Only customers on the Passbase Enterprise beta program should use V3 of the SDK. If you are not on the Passbase Enteprise beta program, you should use V2 of the SDK as V3 contains breaking changes.
You have successfully installed the Passbase SDK!🎉

2. Initialize the SDK

Please only use the publishable API key for all integrations. The secret key should never be exposed or used in a web integration or mobile app since it can access sensitive user data if leaked!
Open your MainActivity in your directory. This was created through the previous step. It will be called something similar to, MainActivity. Add the two import statements to the top of the file:
Kotlin
Java
import com.passbase.passbase_sdk.PassbaseSDK
import com.passbase.passbase_sdk.PassbaseButton
import com.passbase.passbase_sdk.PassbaseSDK;
import com.passbase.passbase_sdk.PassbaseButton;
After that, your need to initialize the SDK with your own publishable API key from your developer dashboard's API settings. See YOUR_PUBLISHABLE_API_KEY in the coding example below:
Kotlin
Java
package com.passbase.androiddemoapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.PassbaseSDK
import com.passbase.passbase_sdk.PassbaseButton
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 2. Initialize object here with own API key
val passbaseRef = PassbaseSDK(this)
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY")
}
}
package com.passbase.androiddemoapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.PassbaseSDK;
import com.passbase.passbase_sdk.PassbaseButton;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 2. Initialize object here with own API key
PassbaseSDK passbaseRef = new PassbaseSDK(this);
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY");
}
}
You have successfully initialized the Passbase SDK in your Android App! 🎉

3. Start the Verification

To start a new verification, you first need to create a verification button. Please ensure that you added both import statements to the top of your file from step 2. You can now do this in two ways:
Keep in mind that in order to successfully finish a verification, you need to pass our liveness detection. Hence, if you develop on a Simulator (e.g. Simulator via Android Studio), you will only see the SDK in UI demo mode. Therefore please use a real device (e.g. an attached Android phone) to fully test and develop with our SDK.

Add Button via Layout / XML

You can create a stylized Passbase button via XML layout like this and give it an id in order to find it later.
<com.passbase.passbase_sdk.PassbaseButton
android:id="@+id/passbaseVerificationButton"
android:layout_width="250dp"
android:layout_height="56dp"
android:layout_marginStart="80dp"
android:layout_marginTop="336dp"
app:backgroundColor="@android:color/white"
app:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

Add Button Programmatically

Or you can create a button programmatically, apply constraints and add it to your view like this.
Kotlin
Java
val verificationButton = PassbaseButton(YOUR_CONTEXT)
PassbaseButton verificationButton = new PassbaseButton(this);
Afterwards a button like this should render in your view.

Start Verification

To start a verification, you can call the startVerification() method. We suggest doing this with an setOnClickListener
Kotlin
Java
val verificationButton = findViewById<PassbaseButton>(R.id.passbaseVerificationButton)
verificationButton.setOnClickListener {
passbaseRef.startVerification()
}
PassbaseButton verificationButton = this.findViewById(R.id.passbaseVerificationButton);
verificationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
passbaseRef.startVerification();
}
});
PassbaseButton inherits from LinearLayout and you can use all the methods that you would usually use for that. Don't forget to add import android.widget.LinearLayout to the top then.

Prefilling Email Address

If you want to prefill a user's email address, to skip the "Approve your Email" screen, you can simply pass the email address into the initialization method.
Kotlin
Java
package com.passbase.androiddemoapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.PassbaseSDK
import com.passbase.passbase_sdk.PassbaseButton
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val passbaseRef = PassbaseSDK(this)
passbaseRef.initialize("YOUR_PUBLISBALE_API_KEY")
// 2. You can add the prefill email option here (optional)
passbaseRef.prefillUserEmail = "[email protected]";
}
}
package com.passbase.androiddemoapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.Passbase;
import com.passbase.passbase_sdk.PassbaseButton;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PassbaseSDK passbaseRef = new PassbaseSDK(this);
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY");
// 2. You can add the prefill email option here
passbaseRef.setPrefillUserEmail("[email protected]");
}
}

Prefilling Country

You can automatically prefill user's country in the drop-down list. This is available programmatically if you pass the prefillCountry parameter to the button like below. An ISO-3166 compliant country code, case insensitive. This will not enable skipping the country selection step.
Kotlin
Java
package com.passbase.androiddemoapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.PassbaseSDK
import com.passbase.passbase_sdk.PassbaseButton
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val passbaseRef = PassbaseSDK(this)
passbaseRef.initialize("YOUR_PUBLISBALE_API_KEY")
// 2. You can add the prefill email option here (optional)
passbaseRef.prefillCountry = "de";
}
package com.passbase.androiddemoapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.Passbase;
import com.passbase.passbase_sdk.PassbaseButton;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PassbaseSDK passbaseRef = new PassbaseSDK(this);
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY");
// 2. You can add the prefill email option here
passbaseRef.setPrefillCountry("de");
}
}

Prefilling metaData

If you are tracking end users in your backend through an internal UUID, transaction number, stripe ID, etc., you can use the metaData object to securely pass encrypted end user information to identify completed verifications. The metadata object requires an encrypted JSON string via the private key encoded in base64.
Value
metaData
Encrypted JSON string via the private key encoded in base64
Kotlin
Java
package com.passbase.androiddemoapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.PassbaseSDK
import com.passbase.passbase_sdk.PassbaseButton
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val passbaseRef = PassbaseSDK(this)
passbaseRef.initialize("YOUR_PUBLISBALE_API_KEY")
// Signed and Armored Metadata, which contain {internal_customer_id: "XYZ", "email": "[email protected]", "country": "de", ...}
passbaseRef.metaData = "AJIZZDIZJADIOAJDOIZJAOIZJDOIAJIODZJIAJDIOZJAIOZDJALANLIKESJIZZOIZDJAOIZJDOZIAJDOIAZJDAZD"
}
package com.passbase.androiddemoapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
// 1. Add import of Passbase SDK and the Passbase Button to the top
import com.passbase.passbase_sdk.Passbase;
import com.passbase.passbase_sdk.PassbaseButton;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PassbaseSDK passbaseRef = new PassbaseSDK(this);
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY");
// Signed and Armored Metadata, which contain {internal_customer_id: "XYZ", "email": "[email protected]", "country": "de", ...}
passbaseRef.setMetaData("AJIZZDIZJADIOAJDOIZJAOIZJDOIAJIODZJIAJDIOZJAIOZDJALANLIKESJIZZOIZDJAOIZJDOZIAJDOIAZJDAZD");
}
}

Add Encryption Key to your Project

Encryption should be completed on the server-side. Once you have completed the encryption, please enter the encryption keys for each individual project within the developer dashboard. The metaData object is then returned on the Passbase API.
Click here to view metaData encryption documentation.

Retrieve MetaData from Passbase API

After a user completes a verification and you receive the VERIFICATION_REVIEWED webhook event, it is time to call the Passbase Get Identity endpoint. Using this API endpoint, you will see the new metaData object returned.
If the public encryption key is not added to the developer dashboard, you will not see the metaData information returned on the API.
{
id: "1234-1234-1234-1234",
resources: [...],
metadata: { internal_customer_id: "XYZ" }
}
You have successfully started your first verification. 🎉

4. Handling Verifications

In some cases it's useful to know if a user has completed the verification flow or canceled it. For this, you can implement the following delegate/callback methods:
Method
Description
onStart
This callback method is triggered once a user starts the verification flow.
onSubmitted
Method that is being called once verification data is submitted to Passbase.
You receive an object called identityAccessKey which can be used to access the identity. Please see our section about Webhooks and API for more information.
onFinish
Method that is being called once a user clicks the "Finish" button. You receive an object called identityAccessKey which can be used to access the identity. Please see our section about Webhooks and API for more information.
onError
This callback method is triggered when a user canceled the verification flow or the verification finished with an error. You can use this to find out if people dropped out of your verification flow.
Error codes:
CANCELLED_BY_USER BIOMETRIC_AUTHENTICATION_FAILED
We also recommend adding this to your setOnClickListener method.
Kotlin
Java
val passbaseRef = PassbaseSDK(this)
// Add here the callbacks
passbaseRef.callback(object : PassbaseSDKListener {
override fun onStart() {
println("MainActivity onStart")
}
override fun onFinish(identityAccessKey: String) {
println("MainActivity onFinish $identityAccessKey")
}
override fun onSubmitted(identityAccessKey: String) {
println("MainActivity onSubmitted $identityAccessKey")
}
override fun onError(errorCode: String) {
println("MainActivity onError $errorCode")
}
})
PassbaseSDK passbaseRef = new PassbaseSDK(this);
// Add here the callbacks
passbaseRef.callback(new PassbaseSDKListener() {
@Override
public void onStart() {
System.out.println("MainActivity onStart");
}
@Override
public void onFinish(@Nullable String identityAccessKey) {
System.out.println("MainActivity onFinish: " + identityAccessKey);
}
@Override
public void onSubmitted(@Nullable String identityAccessKey) {
System.out.println("MainActivity onSubmitted: " + identityAccessKey);
}
@Override
public void onError(@NotNull String errorCode) {
System.out.println("MainActivity onError: " + errorCode);
}
});
We recommend the following process for handling identity verifications:
  1. 1.
    Obtain the authKey of a successfully completed identity verification from the callback method and save it to your DB to the user's profile
  2. 2.
    Set up webhooks to be notified once the identity verification has been processed by our system. Also once you have approved or declined the user in your dashboard
  3. 3.
    Now you can use your own backend to query the details about this identity verification with e.g. the Get Identity call to obtain the details

Identity Access Key as Reference

In order for your application to interoperate with Passbase, you should reference to your users once the Verification is completed.
For that, you will need to keep track of the identityAccessKey returned by the onFinish or onSubmitted callbacks and associate it in your backend with your end users' id. We recommend to save this key after the onSubmitted method from your user's completed verification, or listen for the incoming webhooks to make a call to the Passbase API linking back the email address of the user.

5. UI Customizations

Appearance

Our SDK currently supports a set of customization options which will influence the appearance. To customize the verification flow, please navigate to your developer dashboard's customization section. Here you can choose amongst a variety of colors, fonts, accepted countries & much more.
Customization Section
We also offer a dark mode, which will be automatically triggered if a user has activated this in his system settings.

Language

We support a variety of different languages for the verification flow. As of this writing more than 10 including (English, Spanish, German & many more). If one is missing and you want us to add support for it, please reach out to our customer support.
The SDK automatically detects the language of the user's phone settings. If we support the language, the verification flow will be set to it. Otherwise, the default is English.

6. ProGuard

If you are using ProGuard you might need to add the following options:
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
to ProGuard exceptions
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

Example & Demo App

A full code example for a basic integration can be found below. You can find a demo integration showing how to integrate the Passbase SDK for Android on our Github page.
Kotlin
Java
package com.passbase.androiddemoapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.passbase.passbase_sdk.Passbase
import com.passbase.passbase_sdk.PassbaseButton
import android.graphics.Color
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val passbaseRef = PassbaseSDK(this)
// Initialization and prefilled email
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY")
passbaseRef.prefillUserEmail = "[email protected]";
// Handling verifications via callbacks
passbaseRef.callback(object : PassbaseSDKListener {
override fun onStart() {
println("MainActivity onStart")
}
override fun onFinish(identityAccessKey: String?) {
println("MainActivity onFinish $identityAccessKey")
}
override fun onSubmitted(identityAccessKey: String?) {
println("MainActivity onSubmitted $identityAccessKey")
}
override fun onError(errorCode: String) {
println("MainActivity onError $errorCode")
}
})
val verificationButton = findViewById<PassbaseButton>(R.id.passbaseVerificationButton)
verificationButton.setOnClickListener {
passbaseRef.startVerification()
}
}
}
package com.passbase.androiddemoapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.passbase.passbase_sdk.PassbaseSDK;
import com.passbase.passbase_sdk.PassbaseButton;
import android.graphics.Color;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PassbaseSDK passbaseRef = new PassbaseSDK(this);
// Initialization and prefilled email
passbaseRef.initialize("YOUR_PUBLISHABLE_API_KEY");
passbaseRef.setPrefillUserEmail("[email protected]");
// Handling verifications via callbacks
passbaseRef.callback(new PassbaseSDKListener() {
@Override
public void onStart() {
System.out.println("MainActivity onStart");
}
@Override
public void onFinish(@Nullable String identityAccessKey) {
System.out.println("MainActivity onFinish: " + identityAccessKey);
}
@Override
public void onSubmitted(@Nullable String identityAccessKey) {
System.out.println("MainActivity onSubmitted: " + identityAccessKey);
}
@Override
public void onError(@NotNull String errorCode) {
System.out.println("MainActivity onError: " + errorCode);
}
});
PassbaseButton verificationButton = this.findViewById(R.id.passbaseVerificationButton);
verificationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
passbaseRef.startVerification();
}
});
}
}
You have finished the integration of Passbase for Android! 🎉

Troubleshooting

Camera is not starting in release build

If you experience that camera is not starting in release build make sure you set enableProguardInReleaseBuilds in build.gradle to false. Or add exeptions as described in ProGuard section above.
Last modified 7mo ago