The OkHi android SDK is a seamless way to collect and use accurate customer location information.
The SDK is a customisable UI within your app that enables users to create or lookup existing OkHi locations.
An OkHi location consists of a high accurate GPS pin, a photo of gate and a weblink that enables either to navigate to the location or to plot your user demographics on the OkHi Insights web-app.
OkHi SDK gives your app the ability to collect an address for a user as well as update the user’s address.
The minimum supported SDK version is 23 (android 6.0)
Steps for integration
Add the maven repository into your project build.gradle
Initialize the OkHi SDK by adding the following line in your application class. Initialize takes two parameters: the API key (a string) to use and verify ( a boolean ) to verify the user's created address.
Create a callback to receive the responses from the library
OkHiCallback okHiCallback =newOkHiCallback() { @Overridepublicvoidquerycomplete(JSONObject jsonObject) {//The callback will return the jsonobject once its done. }};
When the user goes through the address creation process successfully, the following json object is returned in the callback.
{"location": {"streetName":"Yellow brick road","lat":-1.2343261,"lng":36.6642569,"placeId":"1A8sxd6V9W","propertyName":"Mitte lane court","directions":"turn is gud","id":"dEwmYjtpqc","url":"https://receive2.okhi.co/dEwmYjtpqc","otherInformation":"Please pet the dog when you arrive" },"user": {"phone":"+254713567907","firstName":"Ramogi","lastName":"Ochola" }}
Returned after the user has successfully completed address creation.
{"message": "fatal_exit","payload": {"Error":"Address creation did not complete" }}
Returned if the user did not complete the address creation
{"message": "fatal_exit","payload": {"Error":"phone is required in user object" }}
Returned if a parameter is missing
{"message": "fatal_exit","payload": {"errorCode":-1,"error":"Location permission not granted","message":"Manifest.permission.ACCESS_BACKGROUND_LOCATION not granted" }}
Returned if address verification is enabled and the app does not have the necessary location permissions allowed.
You can request for the necessary permissions through the SDK as follows
OkHi.requestPermission(activity, integer);
Example as below
public classMainActivityextendsAppCompatActivity {privatestatic final int MY_PERMISSIONS_ACCESS_LOCATION =82; @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//somewhere in your code before calling displayClientOkHi.requestPermission(MainActivity.this,MY_PERMISSIONS_ACCESS_LOCATION); }}
Also you can implement the code below in the same activity to know if you were successful in obtaining necessary permissions from the user.
@Override public voidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {switch (requestCode) {caseMY_PERMISSIONS_ACCESS_LOCATION: {// If request is cancelled, the result arrays are empty.if (grantResults.length>0&& grantResults[0] ==PackageManager.PERMISSION_GRANTED) {// permission was granted, yay! Do the// You can continue with user flow } else {// permission denied, boo! Disable the// verify functionality that depends on this permission. }return; } } }
The SDK has utility method as below to check if its necessary to request for location permission.