OkCollect Android

The OkCollect Android library enables you to launch OkHi from your app and collect accurate addresses from your users.

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

implementation 'com.github.okhi:android-okcollect:v3.2.2'

Check for the latest release on github.

Initialization

Create an instance of okCollect class to be used later in your activity.

public class MainActivity extends AppCompatActivity {

    private OkCollect okCollect;
    
    // define a theme that'll be applied to OkCollect
    private final OkHiTheme theme = new OkHiTheme.Builder("#ba0c2f")
        .setAppBarLogo("https://cdn.okhi.co/icon.png")
        .setAppBarColor("#ba0c2f")
        .build();
        
    // configure any optional features you'd like
    private final OkHiConfig config = new OkHiConfig.Builder()
        .withStreetView()
        .build();
            
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // initiate okcollect using the values defined above
        try {
            okCollect = new OkCollect.Builder(this)
                .withTheme(theme)
                .withConfig(config)
                .build();
        } catch (OkHiException exception) {
            exception.printStackTrace();
        }
    }
}

Usage

Launch the library as follows.


public class MainActivity extends AppCompatActivity {

    OkCollect okCollect;
    
    // define a theme that'll be applied to OkCollect
    OkHiTheme theme = new OkHiTheme.Builder("#ba0c2f")
                .setAppBarLogo("https://cdn.okhi.co/icon.png")
                .setAppBarColor("#ba0c2f")
                .build();
                
    // configure any optional features you'd like
    OkHiConfig config = new OkHiConfig.Builder()
            .withStreetView()
            .build();
                
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            okCollect = new OkCollect.Builder(this)
                .withTheme(theme)
                .withConfig(config)
                .build();
        } catch (OkHiException exception) {
            exception.printStackTrace();
        }
    }
    
    private void launchOkCollect() {
        // define a user
        OkHiUser user = new OkHiUser.Builder("+254711234567")
                .withFirstName("Julius")
                .withLastName("Kiano")
                .build();
        // launch okcollect    
        okCollect.launch(user, new OkCollectCallback<OkHiUser, OkHiLocation>() {
            @Override
            public void onSuccess(OkHiUser user, OkHiLocation location) {
              showMessage("Address created "+user.getPhone()+" "+location.getId());  
            }
    
            @Override
            public void onError(OkHiException e) {
              showMessage("Error "+e.getMessage());
            }
        });
    }
    
    private void showMessage(String message) {
        Log.v("MainActivity", message);
    }
}
                
                

Whenever a user's OkHi address is created or used an SMS is sent to them notifying them of this usage

Whereas OkCollect does provide ways to customise the look and feel of the address creation process as well as alter some of the in built functionality. Due to accessibility concerns, the product will work with select brand colours that provide enough contrast to the text being rendered.

Next steps

Last updated