Upgrading to OkCollect v3.2 & OkVerify v1.3

The latest releases of OkCollect & OkVerify for Android applications offers new features to help you better manage the address creation and verification process

The latest release of OkCollect & OkVerify introduces some new features that not only improves the rate at which users get verified but improves the overall developer experience, streamlining how to authenticate with the library and cut back the amount of code you have to write and maintain. These features include:

  1. Keys and development environments are now required to be part of your AndroidManifest.xml file, eliminating the need to keep track of your application version, name etc using the OkHiContext class.

  2. You can now customize the icon and icon color of the foreground notification.

  3. The foreground service is now turned on by default so you don't have to call the startForeground method after verification starts.

  4. You can now turn off the foreground service or verification all together for a particular user via a POST request using our API.

  5. The foreground service is automatically stopped when an address is verified.

  6. Internal improvements that further enhance the reliability of background work resulting in less data being used by the device as well as consume less battery.

Getting started

Include the new versions of OkCollect & OkVerify

Open your build.gradle and add in the new versions of the libraries

dependencies {
  implementation 'com.github.okhi:android-core:v1.3.0'
  implementation 'com.github.okhi:android-okcollect:v3.2.1'
  implementation 'com.github.okhi:android-okverify:v1.3.0'
}

Authorize your application

Place your provided keys in the AndroidManifest.xml file located under android/app/src/main/AndroidManifest.xml as shown bellow.

<application>
    <meta-data android:name="io.okhi.core.branch_id" android:value="<my_branch_id>" />
    <meta-data android:name="io.okhi.core.client_key" android:value="<my_client_key>" />
    <meta-data android:name="io.okhi.core.environment" android:value="sandbox" /> <!-- set this to prod once ready to go live 🚀 -->
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Remove any instances of OkHiAuth and OkHiContext

Given its required to provide your keys in the Manifest file, remove any instantiations of the OkHiClass and OkHiContext from your source code.

Remove the startForegroundVerification call

Given that we now start the foreground service automatically, there's no need to manually start it

Remove the auth object as a parameter from both OkCollect & OkVerify

Its no longer required to pass in the OkHiAuth object to both OkCollect & OkVerify. They can be initialized as shown bellow. Be sure to wrap it in a try catch block.

private OkCollect okCollect;
private OkVerify okVerify;
private OkHi okhi;

private final OkHiTheme theme = new OkHiTheme.Builder("#ba0c2f").setAppBarLogo("https://cdn.okhi.co/icon.png").setAppBarColor("#ba0c2f").build();
private final OkHiConfig config = new OkHiConfig.Builder().withStreetView().build();

try {
    okCollect = new OkCollect.Builder(this).withTheme(theme).withConfig(config).build();
    okVerify = new OkVerify.Builder(this).build();
} catch (OkHiException exception) {
    exception.printStackTrace();
} finally {
    // define a notification that'll be used to start the foreground service
    int importance = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? NotificationManager.IMPORTANCE_DEFAULT : 3;
    OkVerify.init(getApplicationContext(), new OkHiNotification(
        "Verifying your address",
        "We're currently verifying your address. This won't take long",
        "OkHi",
        "OkHi Address Verification",
        "Alerts related to any address verification updates",
        importance,
        1, // notificationId
        2 // notification request code
    ));
}

Thats it! You're done 🚀 Be sure to checkout the full integration example & more on OkHi foreground's service to customize the notification icon and color

Last updated