OkVerify Android

The OkVerify Android library enables you to verify a user's OkHi address automatically

Getting started

Make sure you have completed the OkHi on your android app steps

Installation

In your app module build.gradle dependency, add the following dependency and sync gradle files

dependencies {
  implementation 'com.github.okhi:android-okverify:v1.2.0'
}

Check for the latest release on github.

Usage

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.

public class MainActivity extends AppCompatActivity {

    private OkVerify okVerify;
    
    @Override
    protected void onCreate(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(), 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,
                R.mipmap.ic_launcher,
                1, // notificationId
                2 // notification request code
        ));
    }
}

Start / Stop OkHi address verification

public class MainActivity extends AppCompatActivity {

    private OkVerify okVerify;
    private OkHiLocation workAddress = new OkHiLocation("<okhi_location_id>", -1.266429, 36.765606);
    private OkHiUser user = new OkHiUser.Builder("+254711234567")
                    .withFirstName("Juliet")
                    .withLastName("Zuri")
                    .build();
    @Override
    protected void onCreate(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(), 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,
                R.mipmap.ic_launcher,
                1, // notificationId
                2 // notification request code
        ));
    }
    
    private void startAddressVerification() {                    
      okVerify.start(user, workAddress, new OkVerifyCallback<String>() {
          @Override
          public void onSuccess(String result) {
            showMessage("Successfully started verification for: " + result);
            startForegroundVerification();
          }
          @Override
          public void onError(OkHiException e) {
            showMessage("Something went wrong: " + e.getCode());
          }
      });
    }
    
    private void stopAddressVerification() {
      OkVerify.stop(getApplicationContext(), work.getId());
    }
    
    private void startForegroundVerification() {
        try {
            // start a foreground service that'll improve the stability and reliability of verification signals
            OkVerify.startForegroundService(getApplicationContext());
        } catch (OkHiException e) {
            e.printStackTrace();
        }
    }
    
    private void stopForegroundVerification() {
        // stops the running foreground service
        OkVerify.stopForegroundService(getApplicationContext());
    }

    private boolean checkForegroundService() {
        // checks if the foreground service is running
        return OkVerify.isForegroundServiceRunning(getApplicationContext());
    }
}

Check out our full OkVerify integration example

FAQs

Building with pro-guard enabled

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 class com.esotericsoftware.** {*;}

-keep class java.beans.** { *; }
-keep class sun.reflect.** { *; }
-keep class sun.nio.ch.** { *; }

-keep class com.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

Last updated