Android

Learn how to integrate your app with the Okra Widget Android SDK

Overview

The Okra Widget SDK is a quick and secure way to link bank accounts to Okra in your Android app. Link is a drop-in module that handles connecting a financial institution to your app (credential validation, multi-factor authentication, error handling, etc). All without passing sensitive personal information to your server.

To get started with Okra Widget for Android, clone the GitHub repository and try out the example application, which provides a reference implementation in Java.

Requirements

  • Android Studio 4.0 or above
  • Android 5.0 (API level 21) or above
  • Check out our Quickstart guide to create your developer account and retrieve your Client Token, API Keys, and Private Keys.
  • Create a sandbox customer, so you can get connecting immediately.

Getting started

This library would help you add the Okra Widget to your native android app in no time. All you need to do is ...

Install

gradle

  1. Add it to your root build.gradle at the end of repositories:
allprojects {
  repositories {
   ...
   maven { url 'https://jitpack.io' }
  }
}
  1. Add the dependency:
dependencies {
 implementation 'ng.okra.com:okra:1.0.0'
 }

Usage versions v2.1-beta and below

ArrayList products = new ArrayList<Enums.Product>();
products.add(Enums.Product.auth);
products.add(Enums.Product.transactions);
OkraOptions okraOptions = new OkraOptions(true, "c81f3e05-7a5c-5727-8d33-1113a3c7a5e4","5d8a35224d8113507c7521ac", products, Enums.Environment.sandbox,"Bassey");
Okra.create(MainActivity.this, okraOptions);

Usage versions v2.2-beta and above

BuildWithShortUrl

This method takes away the burden of customizing your widget in your text editor; instead, it allows you to leverage the Okra dashboard to customize the appearance and features of your widget. After customization, it presents a short URL, which is a vital link for the widget.

This method saves time, and it's a no-code option.

Depending on your logic, you can set up the function registerForActivityResult in your controller or view the model class with the necessary options and call it when needed, which would be most likely when your user triggers a call to action of your choice, in this case, the Raised Button.

val activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()
    ) {
        if (it.resultCode == RESULT_OK && it.data != null) {
            val okraResult = it.data!!.getStringExtra(OkraMainActivity.OKRA_RESULT)
            //Successful operation, get the data and do whatever you want with it.
            Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show()
        } else {
            val okraResult = it.data!!.getStringExtra(OkraMainActivity.OKRA_RESULT)
            Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show()
        }
    }

    val okraOptions = OkraOptions.ShortUrlBuilder("INSERT SHORT URL")
            .build()

    val intent = OkraMainActivity.newIntent(this, okraOptions)
    activityResultLauncher.launch(intent)
public class MainActivity extends AppCompatActivity {

    ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == RESULT_OK && result.getData() != null) {
                    String okraResult = result.getData().getStringExtra(OkraMainActivity.OKRA_RESULT);
                    //Successful operation, get the data and do whatever you want with it.
                    Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show();
                } else {
                    String okraResult = result.getData().getStringExtra(OkraMainActivity.OKRA_RESULT);
                    Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show();
                }
            });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        OkraOptions okraOptions = new OkraOptions.ShortUrlBuilder("Insert short url").build();
        Intent intent = OkraMainActivity.Companion.newIntent(this, okraOptions);
        activityResultLauncher.launch(intent);
    }
}

BuildWithOptions

This method gives you the freedom to code by hand the necessary parameters required to kickstart the SDK.

Using BuildWithOptions lets you customize the appearance, and features and be creative. Hence, it's the best choice for a developer who wants to change their widget's look and feel frequently.

Depending on your logic, you can set up the function registerForActivityResult in your controller or view the model class with the necessary options and call it when needed, which would be most likely when your user triggers a call to action of your choice, in this case, the Raised Button.

val activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()
    ) {
        if (it.resultCode == RESULT_OK && it.data != null) {
            val okraResult = it.data!!.getStringExtra(OkraMainActivity.OKRA_RESULT)
            //Successful operation, get the data and do whatever you want with it.
            Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show()
        } else {
            val okraResult = it.data!!.getStringExtra(OkraMainActivity.OKRA_RESULT)
            Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show()
        }
    }

    val okraOptions = OkraOptions.OptionsBuilder("INSERT KEY HERE","INSERT TOKEN","INSERT ENV HERE","INSERT NAME HERE", "INSERT PRODUCTS HERE")
                    //Add additional properties here.
                    .appId("")
                    .color("")
                    .connectMessage("")
                    .currency("")
                    .isCorporate(true)
                    .build()
    val intent = OkraMainActivity.newIntent(this, okraOptions)
    activityResultLauncher.launch(intent)
public class MainActivity extends AppCompatActivity {

    ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == RESULT_OK && result.getData() != null) {
                    String okraResult = result.getData().getStringExtra(OkraMainActivity.OKRA_RESULT);
                    //Successful operation, get the data and do whatever you want with it.
                    Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show();
                } else {
                    String okraResult = result.getData().getStringExtra(OkraMainActivity.OKRA_RESULT);
                    Toast.makeText(this, okraResult, Toast.LENGTH_SHORT).show();
                }
            });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        OkraOptions okraOptions = new OkraOptions.OptionsBuilder("INSERT KEY HERE","INSERT TOKEN","INSERT ENV HERE","INSERT NAME HERE", "INSERT PRODUCTS HERE")
                    //Add additional properties here.
                    .appId("")
                    .color("")
                    .connectMessage("")
                    .currency("")
                    .isCorporate(true)
                    .build();
        Intent intent = OkraMainActivity.Companion.newIntent(this, okraOptions);
        activityResultLauncher.launch(intent);
    }
}

📘

Checkout a list of all the available Widget Properties to add to your widget options below.

View a complete list of customizable options here

Getting the okra onSuccess and onError response

Okra gives provision to access the response data on the mobile device. Okra wraps the response in the OkraHandler object and passes it back to the View which called it.

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 1) {
            if(resultCode == Activity.RESULT_OK){
                OkraHandler okraHandler = (OkraHandler) data.getSerializableExtra("okraHandler");
                String rr = okraHandler.getData();
                Log.i("okra okraHandler ", okraHandler != null ? okraHandler.getData() : "nothing");

            }
            if (resultCode == Activity.RESULT_CANCELED) {
                //Write your code if there's no result
           }
        }
    }

OkraHandler

NameTypeDefault ValueDescription
isDonebooleanfalseIt indicates if the okra process has finished.
isSuccessfulbooleanfalseIt indicates if the okra process was successful.
hasErrorbooleanfalseIt indicates if the okra process has an error.
DataJsonnullThis is the response that okra provides.

Not a developer?

Get started without writing a single line of code, try the App Builder! Click here to get started.