OkHi Documentation
v6.0.0
Ask or search…
⌃K
Comment on page

Android Library

The suite of OkHi android libraries that will enable you to start collecting and verifying your user's addresses.
To start verifying address you need to integrate two libraries. OkCollect & OkVerify.
  • OkCollect - enables you to launch OkHi from your app and collect accurate addresses from your users.
  • OkVerify - enables you to verify the addresses created from OkCollect

Installation

Androidx

Please make sure AndroidX is enabled in your project by modifying android/gradle.properties and adding 2 lines:
android.useAndroidX=true
android.enableJetifier=true

Add the JitPack repository to your build file

gradle
maven
sbt
leiningen
allprojects {
repositories {
maven { url "https://repo.okhi.io/artifactory/maven" } // <- add this
//..//
}
}
<repositories>
<repository>
<id>repo.okhi.io</id>
<url>https://repo.okhi.io/artifactory/maven</url>
</repository>
</repositories>
resolvers += "repo.okhi.io" at "https://repo.okhi.io/artifactory/maven"
:repositories [["repo.okhi.io" "https://repo.okhi.io/artifactory/maven"]]

Add the OkHi Core library dependencies

gradle
maven
sbt
leiningen
dependencies {
implementation 'io.okhi.android:core:1.7.15'
implementation 'io.okhi.android:okcollect:3.3.20'
implementation 'io.okhi.android:okverify:1.9.31'
}
<dependency>
<groupId>repo.okhi.io</groupId>
<artifactId>android-core</artifactId>
<version>v1.7.15</version>
<artifactId>android-okcollect</artifactId>
<version>v3.3.20</version>
<artifactId>android-okverify</artifactId>
<version>v1.9.31</version>
</dependency>
libraryDependencies += "repo.okhi.io" % "android-core" % "v1.7.15"
libraryDependencies += "repo.okhi.io" % "android-okcollect" % "v3.3.20"
libraryDependencies += "repo.okhi.io" % "android-okverify" % "v1.9.31"
:dependencies [[com.github.OkHi/android-core "v1.7.15"]]
:dependencies [[com.github.OkHi/android-okcollect "v3.3.20"]]
:dependencies [[com.github.OkHi/android-okverify "v1.9.31"]]
Check for the latest release on GitHub:
​android-core​
​android-okcollect​
​android-okverify​

Configure your app

Open your AndroidManifest.xml located under android/app/src/main/AndroidManifest.xml and add:
  1. 1.
    your credentials (obtain these by filling out this form) as shown below​.
  2. 2.
    required permissions: ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION
<manifest ...>
​
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
...
<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="prod" />
<meta-data android:name="io.okhi.core.platform" android:value="android" />
...
</application>
​
</manifest>
If you're targeting Android versions >= 8 you need to make sure your users select on "Allow always" when granting permissions otherwise the verification process won't work. See our best practices section

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.
Java
Kotlin
1
public class Sample extends AppCompatActivity {
2
​
3
private OkHi okhi;
4
private OkCollect okCollect;
5
private OkVerify okVerify;
6
​
7
@Override
8
protected void onCreate(Bundle savedInstanceState) {
9
super.onCreate(savedInstanceState);
10
setContentView(R.layout.activity_main);
11
setUpOkHi();
12
​
13
Button btn = findViewById(R.id.btnSubmit);
14
btn.setOnClickListener(view -> handleButtonClick());
15
}
16
​
17
private void handleButtonClick() {
18
OkHiUser user = new OkHiUser.Builder("+234xxxxx") // It is important to provide your actual phone number, as a message will be sent to this number
19
.withFirstName("Gift")
20
.withLastName("Moore")
21
.withEmail("[email protected]") // It is important to use your actual email address, an email may be sent to the provided address
22
.build();
23
24
requestPermissions(user)
25
}
26
27
private void requestPermissions(OkHiUser user) {
28
okhi.requestEnableVerificationServices(new OkHiRequestHandler<Boolean>() {
29
@Override
30
public void onResult(result: Boolean) {
31
if (result) {
32
startAddressCreation(user);
33
}
34
}
35
36
@Override
37
public void onError(e: OkHiException) {
38
e.printStackTrace()
39
}
40
})
41
}
42
​
43
private void startAddressCreation(OkHiUser user) {
44
okCollect.launch(user, OkCollectLaunchMode.CREATE, new OkCollectCallback<OkHiUser, OkHiLocation>() {
45
@Override
46
public void onSuccess(OkHiUser okHiUser, OkHiLocation location) {
47
startAddressVerification(okHiUser, location);
48
}
49
@Override
50
public void onClose() {
51
Toast.makeText(Sample.this, "User closed", Toast.LENGTH_LONG).show();
52
}
53
@Override
54
public void onError(OkHiException e) {
55
56
Toast.makeText(Sample.this, e.getCode() + ":" + e.getMessage(), Toast.LENGTH_LONG).show();
57
}
58
});
59
}
60
​
61
private void startAddressVerification(OkHiUser user, OkHiLocation location) {
62
okVerify.start(user, location, new OkVerifyCallback<String>() {
63
@Override
64
public void onSuccess(String result) {
65
Toast.makeText(Sample.this, "Started verification for: " + result, Toast.LENGTH_LONG).show();
66
}
67
​
68
@Override
69
public void onError(OkHiException e) {
70
Toast.makeText(Sample.this, e.getCode() + ":" + e.getMessage(), Toast.LENGTH_LONG).show();
71
}
72
});
73
}
74
​
75
private void setUpOkHi() {
76
​
77
final OkHiTheme theme = new OkHiTheme.Builder("#333333").setAppBarLogo("https://cdn.okhi.co/icon.png").setAppBarColor("#333333").build();
78
final OkHiConfig config = new OkHiConfig.Builder().withStreetView().build();
79
​
80
int importance = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? NotificationManager.IMPORTANCE_DEFAULT : 3;
81
OkVerify.init(getApplicationContext(), new OkHiNotification(
82
"Verifying your address",
83
"We're currently verifying your address. This won't take long",
84
"OkHi_Test",
85
"OkHi Address Verification",
86
"Alerts related to any address verification updates",
87
importance,
88
1, // notificationId
89
2 // notification request code
90
));
91
​
92
try {
93
okhi = new OkHi(this);
94
okCollect = new OkCollect.Builder(this).withTheme(theme).withConfig(config).build();
95
okVerify = new OkVerify.Builder(this).build();
96
} catch (Exception e) {
97
e.printStackTrace();
98
}
99
}
100
​
101
@Override
102
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
103
super.onActivityResult(requestCode, resultCode, data);
104
okhi.onActivityResult(requestCode, resultCode, data);
105
}
106
​
107
@Override
108
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
109
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
110
okhi.onRequestPermissionsResult(requestCode, permissions, grantResults)
1
​
2
class MainActivity : AppCompatActivity() {
3
private lateinit var okhi: OkHi
4
private lateinit var okCollect: OkCollect
5
private lateinit var okVerify: OkVerify
6
​
7
override fun onCreate(savedInstanceState: Bundle?) {
8
super.onCreate(savedInstanceState)
9
setContentView(R.layout.activity_main)
10
setUpOkHi()
11
}
12
​
13
public fun handleButtonPress(v: View) {
14
requestPermissions()
15
}
16
​
17
private fun requestPermissions() {
18
okhi.requestEnableVerificationServices(object : OkHiRequestHandler<Boolean> {
19
override fun onResult(result: Boolean) {
20
if (result) {
21
startAddressCreation();
22
}
23
}
24
override fun onError(e: OkHiException) {
25
e.printStackTrace()
26
}
27
})
28
}
29
​
30
private fun startAddressCreation() {
31
val user = OkHiUser.Builder("+234xxxxx") // It is important to provide your actual phone number, as a message will be sent to this number
32
.withFirstName("Gift")
33
.withLastName("Moore")
34
.withEmail("[email protected]") // It is important to use your actual email address, an email may be sent to the provided address
35
.build()
36
37
okCollect.launch(user, object : OkCollectCallback<OkHiUser, OkHiLocation> {
38
override fun onSuccess(okHiUser: OkHiUser, location: OkHiLocation) {
39
startAddressVerification(okHiUser, location)
40
}
41
override fun onClose() {
42
// user closed okcollect
43
}
44
override fun onError(e: OkHiException) {
45
e.printStackTrace()
46
}
47
})
48
}
49
​
50
private fun startAddressVerification(user: OkHiUser, location: OkHiLocation) {
51
okVerify.start(user, location, object : OkVerifyCallback<String> {
52
override fun onSuccess(result: String) {
53
Log.v("OkVerify", "Verification started for: $result")
54
}
55
override fun onError(e: OkHiException) {
56
e.printStackTrace()
57
}
58
})
59
}
60
​
61
private fun setUpOkHi() {
62
val theme = OkHiTheme.Builder("#333333").setAppBarLogo("https://cdn.okhi.co/icon.png").setAppBarColor("#333333").build()
63
val config = OkHiConfig.Builder().withStreetView().build()
64
val importance = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) NotificationManager.IMPORTANCE_DEFAULT else 3
65
OkVerify.init(applicationContext, OkHiNotification(
66
"Verifying your address",
67
"We're currently verifying your address. This won't take long",
68
"OkHi_Test",
69
"OkHi Address Verification",
70
"Alerts related to any address verification updates",
71
importance,
72
1,
73
2
74
)
75
)
76
try {
77
okhi = OkHi(this)
78
okCollect = OkCollect.Builder(this).withTheme(theme).withConfig(config).build()
79
okVerify = OkVerify.Builder(this).build()
80
} catch (e: Exception) {
81
e.printStackTrace()
82
}
83
}
84
​
85
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
86
super.onActivityResult(requestCode, resultCode, data)
87
okhi.onActivityResult(requestCode, resultCode, data)
88
}
89
​
90
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String?>, grantResults: IntArray) {
91
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
92
okhi.onRequestPermissionsResult(requestCode, permissions, grantResults)
93
}
94
}

Next steps

Review the API references
​OkHi Core​
​OkHi OkCollect​
​OkHi OkVerify​