Skip to main content

Android Elements SDK

Android Elements SDK

basistheory-android

Basis Theory Android Elements are simple, secure, developer-friendly inputs that empower consumers to collect sensitive data from their users directly to Basis Theory's certified vault.

Think about it as an isolated sandbox within your mobile application that your end users are able to seamlessly interact with, and which securely communicates with the Basis Theory Vault. Sensitive data is not directly exposed to your application code, which keeps your mobile application out of compliance scope.

Here's how we make this possible:

  • Install our Android SDK into your mobile application
  • Build forms using our Element input components
  • Interact with the Basis Theory API using Element references, not plaintext data
  • Own your UI/UX by fully customizing how Elements are styled

Collect Sensitive Data

Data entered by your end users into Elements is tokenized and secured within Basis Theory's certified Vault.

Our SDKs provide several types of inputs to collect various types of data, such as the CardNumberElement for collecting credit card data and TextElement for collecting arbitrary textual data.

Elements can be configured to support custom input masking, validation, and transformation rules to satisfy your use cases.

Reveal Sensitive Data

Tokens stored within the Basis Theory Vault can be securely revealed to end users without accessing the plaintext data directly within your application code.

The ability to reveal sensitive data on Android is not yet generally available. If you are interested in using this feature on Android, please email us at info@basistheory.com to join our early access program.

Before You Begin

Basis Theory Android Elements require the use of an API Key associated with a Public Application, which only allows token:create and token:update permissions to mitigate the risk that these API keys may be publicly exposed within your frontend applications.

To create one, login into our Portal and create a new "Public" Application with the permissions you require.

Installation

Requirements

  • Android 5.0+ (API level 21+)
  • AndroidX

Gradle

Add this dependency to your project's build file:

  repositories {
maven { url 'https://jitpack.io' }
}

dependencies {
implementation 'com.github.basis-theory:basistheory-android:<version>'
}

The latest release version can be found in GitHub.

Basic Usage

Simply include one or more elements within your application's views:

<com.basistheory.android.view.CardNumberElement
android:id="@+id/card_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.basistheory.android.view.CardExpirationDateElement
android:id="@+id/expiration_date"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.basistheory.android.view.CardVerificationCodeElement
android:id="@+id/cvc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Then tokenize the user input by referencing these elements. This can be wired up in response to a button click, or any other user action.

val cardNumberElement = findViewById(R.id.card_number)
val cardExpirationDateElement = findViewById(R.id.expiration_date)
val cardVerificationCodeElement = findViewById(R.id.cvc)

val bt = BasisTheoryElements.builder()
.apiKey(myPublicApiKey)
.build()

runBlocking {
val tokenizeResponse = bt.tokenize(object {
val type = "card"
val data = object {
val number = cardNumberElement
val expiration_month = cardExpirationDateElement.month()
val expiration_year = cardExpirationDateElement.year()
val cvc = cardVerificationCodeElement
}
})

// send the tokens within tokenizeResponse to your backend
}

A full example Android app is included within the example module within the GitHub repo or explore all the supported Element Types.