Migrating to the latest library How to migrate to the latest release
Our Android libraries have been updated to include the latest features from OkHi, such as the ability to pass your own system user IDs and enhanced security updates while providing a simpler and cleaner API.
Please follow these steps if you are using older library versions.
Change your compile SDK
The OkHi libraries target Android devices >= SDK 21. Make sure you've updated your compileSdkVersion
& targetSdkVersion
to 34 in your app/build.gradle
file.
Copy android {
namespace = "io.okhi.okhiandroidverificationdemo"
compileSdk = 34
defaultConfig {
applicationId = "io.okhi.okhiandroidverificationdemo"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
}
buildTypes { ... }
compileOptions { ... }
}
dependencies {
implementation 'io.okhi.android:core:1.7.31'
implementation 'io.okhi.android:okverify:1.9.66'
implementation 'io.okhi.android:okcollect:3.3.45'
}
Within your AndroidManifest.xml
, inside application
, remove this line as it is no longer needed by our library.
Copy < meta-data android : name = "io.okhi.core.platform" android : value = "android" />
Launch okCollect Function
The function has changed from this:
Copy okCollect . launch (user , OkCollectLaunchMode . CREATE , new OkCollectCallback < OkHiUser , OkHiLocation >() {
@ Override
public void onSuccess ( OkHiUser okHiUser , OkHiLocation location) {
startAddressVerification(okHiUser , location) ;
}
@ Override
public void onClose () {
Toast . makeText ( Sample . this , "User closed" , Toast . LENGTH_LONG ) . show ();
}
@ Override
public void onError ( OkHiException e) {
Toast . makeText ( Sample . this , e . getCode () + ":" + e . getMessage () , Toast . LENGTH_LONG ) . show ();
}
});
To this which has one less parameter which is the removal of OkCollectLaunchMode.CREATE and OkCollectCallback that has also changed.
The onSuccess function has also been updated.
Copy okCollect . launch ( createOkHiUser() , new OkCollectCallback < OkCollectSuccessResponse >() {
@ Override
public void onSuccess ( OkCollectSuccessResponse response) {
startAddressVerification(response) ;
}
@ Override
public void onClose () {
showMessage( "User closed." ) ;
}
@ Override
public void onError ( OkHiException e) {
showMessage( e . getCode() + ":" + e . getMessage()) ;
}
});
To accessing the user and location properties, you do this:
Copy OkHiUser user = response . getUser ();
OkHiLocation location = response . getLocation ();
OkHiUser
This builder has changed from this:
Copy OkHiUser user = new OkHiUser . Builder ( "+234..." )
. withFirstName ( "Jane" )
. withLastName ( "Doe" )
. withEmail ( "jane@okhi.co" )
. build ();
To this which has the withAppUserId for passing your system's user ID if you want to pass it
Copy OkHiUser user = new OkHiUser . Builder ( "+254..." )
. withFirstName ( "Jane" )
. withLastName ( "Doe" )
. withEmail ( "jane@okhi.co" )
. withAppUserId ( "abcd1234" )
. build ();
Start Verification Function
The function has changed from this:
Copy okVerify . start (user , location , new OkVerifyCallback < String >() {
@ Override
public void onSuccess ( String result) {
Toast . makeText ( Sample . this , "Started verification for: " + result , Toast . LENGTH_LONG ) . show ();
}
@ Override
public void onError ( OkHiException e) {
Toast . makeText ( Sample . this , e . getCode () + ":" + e . getMessage () , Toast . LENGTH_LONG ) . show ();
}
});
To this which has one less parameter which is all combined as a response.
Copy okVerify . start (response , new OkVerifyCallback < String >() {
@ Override
public void onSuccess ( String locationId) {
showMessage( "Successfully started verification for: " + locationId) ;
}
@ Override
public void onError ( OkHiException e) {
showMessage( e . getCode() + ":" + e . getMessage()) ;
}
});
OkCollect.Builder
OkCollect.Builder no longer throws an exception so you don't need to wrap it in a try-and-catch.
Copy //try {
okhi = new OkHi( this ) ;
okCollect = new OkCollect . Builder ( this ) . withTheme (theme) . withConfig (config) . build ();
okVerify = new OkVerify . Builder ( this ) . build ();
//} catch (Exception e) {
// e.printStackTrace();
//}