Skip to main content

Groups (Android SDK)

A Group lets you treat multiple secure components as a single unit. The Group API supports two distinct use cases:

  • Validation - checking that two or more fields hold identical values (for example, password and confirm-password) without exposing the underlying plaintext.
  • Bulk tokenization - submitting several secure fields to Weavr in a single call and receiving one token per field.

UXComponents.createGroup and the Group class are part of the Weavr Components SDK (io.weavr.components).

Create a group

Pass the components you want to group and the activity context. Group members can be any tokenizable secure components - for example, two SecurePasswordEditText views for a password-confirmation flow:

val passwordGroup = UXComponents.createGroup(
context = this,
arrayListOf(binding.password, binding.passwordConfirm),
)

Manage group membership

Components can be added and removed after the group has been created - useful when fields appear or disappear conditionally (for example, an extra security question that only some users see):

// Add a previously hidden field once it becomes visible.
passwordGroup.addComponents(arrayListOf(binding.securityAnswer))

// Remove a field if the user opts out.
passwordGroup.removeComponents(arrayListOf(binding.securityAnswer))

Validating that fields match

match() returns true when all components currently in the group contain identical values. Typical use is wiring it to your form's submit handler:

binding.submit.setOnClickListener {
if (passwordGroup.match()) {
// Inputs are identical - proceed to tokenize and submit.
} else {
Toast.makeText(this, "Passwords don't match", Toast.LENGTH_SHORT).show()
}
}

match() is a local-only check - it doesn't tokenizeTokenize Replace a card's primary account number (PAN) with a unique digital token that stands in for the real card during a transaction. When a cardholder adds a card to Apple Pay or Google Pay via push provisioning, the wallet provider stores a device-specific token rather than the underlying PAN, so the real card number isn't exposed on the device or shared with merchants. the fields or contact our backend.

Bulk tokenization

createToken tokenizesTokenize Replace a card's primary account number (PAN) with a unique digital token that stands in for the real card during a transaction. When a cardholder adds a card to Apple Pay or Google Pay via push provisioning, the wallet provider stores a device-specific token rather than the underlying PAN, so the real card number isn't exposed on the device or shared with merchants. every component in the group in one call and returns a map keyed by the field keys you supply. Provide one entry in fieldKeys per component, in the same order the components were added to the group - the resulting map associates each key with the token for that component:

passwordGroup.createToken(
fieldKeys = arrayListOf("password", "passwordConfirm"),
callBack = object : WeavrResult<Map<String, String?>, ErrorResponse> {
override fun onSuccess(result: Map<String, String?>?) {
val passwordToken = result?.get("password")
val confirmToken = result?.get("passwordConfirm")
// Submit the tokens to your backend.
}

override fun onFailure(error: ErrorResponse) {
Log.d(TAG, "Tokenization failed: $error")
}
},
)
Field-key count must match component count

The number of entries in fieldKeys must equal the number of components currently in the group. Mismatched counts cause the call to fail.