Installation
First, add the Berbix Maven repository to your Gradle repositories in your project's build.gradle
file.
allprojects {
repositories {
// Existing repositories, like google() and jcenter()
maven {
url "https://storage.googleapis.com/berbix-mobile-releases/repo"
}
}
}
Next, add the Berbix Android SDK to your module dependencies.
dependencies {
// Insert line below to include our client library as a dependency.
implementation 'com.berbix:berbixverify:1.1.4'
}
Lastly, ensure that you have enabled camera and internet access in your app manifest.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
Usage
To initialize the Berbix Verify flow, refer to the code sample below and replace your client_token
for your_token_here
. Please see our Integration Guide for more details on initializing the Berbix Verify flow and integrating Berbix APIs.
class VerifyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
setContentView(R.layout.verify_activity)
findViewById<Button>(R.id.startFlowButton).setOnClickListener {
startBerbix()
}
}
fun startBerbix() {
val token = "your_token_here" // Fetch client token from the backend
val sdk = BerbixSDK()
val config = BerbixConfigurationBuilder().
setClientToken(token).
build()
sdk.startFlow(this, config)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == BerbixConstants.REQUEST_CODE_BERBIX_FLOW) {
when (BerbixResultStatus.getStatus(resultCode)) {
BerbixResultStatus.SUCCESS -> {
Log.e("berbix-result", "success!")
}
BerbixResultStatus.ERROR -> {
Log.e("berbix-result", "error thrown")
}
BerbixResultStatus.NO_CAMERA_PERMISSIONS -> {
Log.e("berbix-result", "no camera permissions")
}
BerbixResultStatus.USER_EXIT -> {
Log.e("berbix-result", "user exited")
}
BerbixResultStatus.UNABLE_TO_LAUNCH_CAMERA -> {
Log.e("berbix-result", "could not launch the camera")
}
}
}
}
}
public class VerifyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.verify_activity);
startBerbix();
}
private void startBerbix() {
BerbixSDK sdk = new BerbixSDK();
final BerbixConfiguration config = new BerbixConfigurationBuilder()
.setClientToken("your_token_here")
.build();
sdk.startFlow(this, config);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == BerbixConstants.REQUEST_CODE_BERBIX_FLOW) {
switch (BerbixResultStatus.getStatus(resultCode)) {
case SUCCESS:
Log.e("berbix-verify", "flow completed");
break;
case USER_EXIT:
Log.e("berbix-verify", "user exited flow");
break;
case NO_CAMERA_PERMISSIONS:
Log.e("berbix-verify", "no camera permission");
break;
case UNABLE_TO_LAUNCH_CAMERA:
Log.e("berbix-verify", "could not launch camera");
break;
case ERROR:
Log.e("berbix-verify", "error occurred");
break;
case UNEXPECTED_RESULT_STATUS:
Log.e("berbix-verify", "unexpected response code received");
break;
}
}
}
}
ProGuard Rules
If you're using ProGuard in your Android application, you'll need to include the following rules to initialize the Berbix SDK:
-keep class com.berbix.berbixverify.request.** { *; }
-keep class sun.misc.Unsafe { *; }
Reference
BerbixSDK Methods
constructor()
Constructs a Berbix SDK client. This can be used subsequently to invoke the Berbix flow within your app.
void startFlow(Context context, BerbixSDKOptions options)
Starts the Berbix flow and immediately takes control of the user interface. This is the most basic invocation of the flow. Upon completion of the flow, the user interface control will be returned to the app and the onActivityResult will be called with the appropriate request and result codes.
BerbixSDKConfigurationBuilder Methods
constructor()
Creates a new options builder with the default initial state.
BerbixSDKOptionsBuilder setClientToken(String clientToken)
Sets the client token for the session. This value is fetched from the Berbix API upon creation of a transaction.
Updated 7 months ago