Android Integration
The Embedded Flow for Android is a flexible module designed to integrate seamlessly into your mobile application. It enables users to complete their onboarding process directly within the app, without disrupting their experience or requiring them to leave the application. This method ensures that user onboarding is conducted smoothly and securely, delivering a consistent and uninterrupted experience throughout the process.
Integration pre-requisites
- Client ID: Unique identifier provided by your Account Manager.
- Journey ID: Unique identifier for your onboarding journey, containing configurations provided by your Account Manager.
- API Key: Secure token to authorize access to specific journeys provided by your Account Manager.
- Android Minimum SDK: minSdkVersion -> API 21 (Lollipop, 5.0) or higher
The prerequisite to integrate Connect SDK directly into the mobile integration is Android min SDK should be
- minSdkVersion -> API 21 (Lollipop, 5.0) or higher.
Step-by-Step Integration
- Add Dependencies:
- Update your project-level build.gradle file to include the Connect repository:
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://android-connect-plugin.s3.ap-south-1.amazonaws.com"
}
}
}
- Add the Connect SDK dependency to your app-level build.gradle file:
dependencies{
...
implementation group: 'com.equal.connectsdk', name: 'connectsdk', version: '1.0.4', ext: 'aar', classifier: 'release'
...
}
- Initialise SDK:
// In the root activity -> onCreate add below line.
EPlugin.getInstance().initSDK(this, SDKEnvironment.TEST); // For prod SDKEnvironment.PROD
// Register for Event Results
EPlugin.getInstance().registerHandler(resEvent -> {
switch (resEvent.getEventType()) {
case LOG:
if (resEvent.getEventData() instanceof EventPluginData) {
EventPluginData eventData = (EventPluginData) resEvent.getEventData();
// To Log the SDK LOGS
}
break;
case CLOSED:
if (resEvent.getEventData() instanceof ClosePluginData) {
ClosePluginData eventData = (ClosePluginData) resEvent.getEventData();
// CLOSE EVENT To handle on completed flow
// Handle fallback here.
}
break;
case COMPLETED:
if (resEvent.getEventData() instanceof CompletePluginData) {
CompletePluginData eventData = (CompletePluginData) resEvent.getEventData();
//Hanlde CompletePluginData
}
break;
case ERROR:
if (resEvent.getEventData() instanceof ErrorPluginData) {
ErrorPluginData errorPluginData = (ErrorPluginData) resEvent.getEventData();
//errorPluginData.getErrorCode() -> Error Code
//errorPluginData.getMessage()() -> Error Details
// Handle fallback here. Based on the error codes.
}
break;
}
});
// Update Inputs to Connect SDK
EConnectPluginReq eConnectPluginReq = new EConnectPluginReq();
eConnectPluginReq.setApiKey("<API Key provided by Equal>");
eConnectPluginReq.setEnv(SDKEnvironment.TEST); // For production use SDKEnvironment.PROD
eConnectPluginReq.setClientId("<Client ID shared by Equal>");
eConnectPluginReq.setJourneyId("<JourneyId ID shared by Equal>");
eConnectPluginReq.setMobileNumber("<Mobile Number>");
//Launch SDK
EPlugin.getInstance().launchSdk(this, eConnectPluginReq);
// In the root activity -> onCreate add below line.
EPlugin.getInstance().initSDK(this, SDKEnvironment.TEST); // For prod SDKEnvironment.PROD
// Register for Event Results
EPlugin.getInstance().registerHandler { resEvent: PluginEvent ->
when (resEvent.eventType) {
EventType.EVENT -> if (resEvent.eventData is EventPluginData) {
val eventData = resEvent.eventData as EventPluginData
// Handle event Data
}
EventType.CLOSED -> if (resEvent.eventData is ClosePluginData) {
val eventData = resEvent.eventData as ClosePluginData
// Handle Close response
}
EventType.COMLETED -> if (resEvent.eventData is CompletePluginData) {
runOnUiThread {
val eventData =
resEvent.eventData as CompletePluginData
// Handle successful response. `eventData.eventModel.data` will contain fields to autofill.
}
}
EventType.ERROR -> {
//Handle fallback
}
}
}
// Update Inputs to Connect SDK
val eConnectPluginReq = EConnectPluginReq()
eConnectPluginReq.apiKey = "<API Key provided by Equal>"
eConnectPluginReq.env = SDKEnvironment.TEST // For production use SDKEnvironment.PROD
eConnectPluginReq.clientId = "<Client ID shared by Equal>"
eConnectPluginReq.journeyId = "<Journey ID shared by Equal>"
eConnectPluginReq.mobileNumber = "<Mobile Number>"
//Launch SDK
EPlugin.getInstance().launchSdk(this, eConnectPluginReq)
- Handle SDK Responses
- onComplete Response
case COMPLETED:
if (resEvent.getEventData() instanceof CompletePluginData) {
CompletePluginData eventData = (CompletePluginData) resEvent.getEventData();
// Access the completed profile data
Map<String, String> profileAttributes = eventData.getData();
String name = profileAttributes.get("name");
// Handle other profile attributes as needed
}
break;
- Exchange authCode for Tokens
String authCode = "<authCode obtained from CompletePluginData>";
String tokenUrl = "https://api.test.equal.in/auth/token?code=" + authCode; // Use PROD URL for production
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(tokenUrl)
.addHeader("Authorization", "Basic " + Base64.encodeToString("<Client ID>:<Client Secret>".getBytes(), Base64.NO_WRAP))
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
String responseBody = response.body().string();
JSONObject jsonObject = new JSONObject(responseBody);
String accessToken = jsonObject.getString("access_token");
String idToken = jsonObject.getString("id_token");
// Use the tokens as needed
} else {
// Handle unsuccessful response
}
}
});
Status Codes
Code | Property Name | Description |
---|---|---|
CONNECT_PROFILE_FOUND | CompletePluginData.EventData.eventName | Profile Fetched in the Connect Journey |
CONNECT_RETURNING_USER | CompletePluginData.EventData.eventName | Repeat User for the Business and same Connect Journey request limit |
CONNECT_NO_PROFILE | CompletePluginData.EventData.eventName | No Profile Data Found. |
CONFIG_ERROR | ErrorPluginData | Wrong inputs from the client. |
INTERNAL_ERROR | ErrorPluginData | When an error occurs in the connection flow. |
Updated 3 months ago