Create an instance of the OkVerify class to be used later in your class.
Make sure to invoke the static init method once on app start.
publicclassMainActivityextendsAppCompatActivity {privateOkVerify okVerify; @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_main); okVerify =new OkVerify.Builder(auth,this).build();// Should be invoked one time on app start. // (optional) OkHiNotification, use to start a foreground service to transmit verification signals to OkHi servers
int importance =Build.VERSION.SDK_INT>=Build.VERSION_CODES.N?NotificationManager.IMPORTANCE_DEFAULT:3;OkVerify.init(getApplicationContext(),newOkHiNotification("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,R.mipmap.ic_launcher,1,// notificationId2// notification request code )); }}
Start / Stop OkHi address verification
publicclassMainActivityextendsAppCompatActivity {privateOkVerify okVerify;privateOkHiLocation workAddress =newOkHiLocation("<okhi_location_id>",-1.266429,36.765606);privateOkHiUser user =new OkHiUser.Builder("+254711234567").withFirstName("Juliet").withLastName("Zuri").build(); @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_main); okVerify =new OkVerify.Builder(auth,this).build();// Should be invoked one time on app start. // (optional) OkHiNotification, use to start a foreground service to transmit verification signals to OkHi servers
int importance =Build.VERSION.SDK_INT>=Build.VERSION_CODES.N?NotificationManager.IMPORTANCE_DEFAULT:3;OkVerify.init(getApplicationContext(),newOkHiNotification("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,R.mipmap.ic_launcher,1,// notificationId2// notification request code )); }privatevoidstartAddressVerification() { okVerify.start(user, workAddress,newOkVerifyCallback<String>() { @OverridepublicvoidonSuccess(String result) {showMessage("Successfully started verification for: "+ result);startForegroundVerification(); } @OverridepublicvoidonError(OkHiException e) {showMessage("Something went wrong: "+e.getCode()); } }); }privatevoidstopAddressVerification() {OkVerify.stop(getApplicationContext(),work.getId()); }privatevoidstartForegroundVerification() {try {// start a foreground service that'll improve the stability and reliability of verification signalsOkVerify.startForegroundService(getApplicationContext()); } catch (OkHiException e) {e.printStackTrace(); } }privatevoidstopForegroundVerification() {// stops the running foreground serviceOkVerify.stopForegroundService(getApplicationContext()); }privatebooleancheckForegroundService() {// checks if the foreground service is runningreturnOkVerify.isForegroundServiceRunning(getApplicationContext()); }}
If you have minifyEnabled set to true in your build.gradle file located android/app/build.gradle, you'll need to modify your proguard-rules.pro file, located android/app/proguard-rules.proas shown bellow to include classes required by the library to run.
-dontwarn sun.reflect.**-dontwarn java.beans.**-dontwarn sun.nio.ch.**-dontwarn sun.misc.**-keep classcom.esotericsoftware.** {*;}-keep classjava.beans.** { *; }-keep classsun.reflect.** { *; }-keep classsun.nio.ch.** { *; }-keep classcom.snappydb.** { *; }-dontwarn com.snappydb.**# If you don't use OkHttp as a dep and the following-dontwarn org.codehaus.mojo.animal_sniffer.*-dontwarn javax.annotation.**-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase-dontwarn org.codehaus.mojo.animal_sniffer.*-dontwarn okhttp3.internal.platform.ConscryptPlatform-dontwarn org.conscrypt.ConscryptHostnameVerifier