How to integrate Android SDK with the client application

Eazyshow > How to integrate Android SDK with the client application
Share this article

Overview

The document describes how to integrate Eazyshow platform into an Android application.

Dependencies

Add these dependencies to build.gradle:

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

Usage

1. Add eazyshow session WebView item to the desired place

<WebView android:id="@+id/eazyshowWebView" 
         android:layout_width="match_parent"
         android:layout_height="match_parent" /

2. Get account details

Token

Account ID

3. Initialize User and Assignment objects

final User user = new User("1234567890", "Test", "User");
final Assignment assignment = new Assignment("android-sdk-test", "12345678");

User details are arbitrary values that should be taken from the end client data.

4. Initialize eazyshow Session object

final WebView webview = findViewById(R.id.eazyshowWebView);
final LiveSession session = new LiveSession(this /* Parent activity object*/, webview);

5 . Create class that will handle events coming from the webview by implementing Android Handler.Callback interface Here is an example handler that verifies client photo.

private static class ValidateSelfieCallback implements Handler.Callback {

    private final LiveSession session;
    private final boolean saveValidationImage;

    public ValidateSelfieCallback(LiveSession session, boolean saveValidationImage) {
        this.session = session;
        this.saveValidationImage = saveValidationImage;
    }

    @Override
    public boolean handleMessage(@NonNull Message message) {
        final SessionEvent event = SessionEvent.values()[message.arg1];
        Log.v("DemoActivity", "Message received: " + event);
        if (event == SessionEvent.EVENT) {
            final Bundle bundle = message.getData();
            final String eventName = bundle.getString("name");
            final String eventData = bundle.getString("data");

            switch (eventName) {
                case "vsValidateSelfie":
                    validateSelfie(eventData);
                    return true;
            }
            return false;
        }
        return false;
    }

    private void validateSelfie(String imageData) {
        if (saveValidationImage) {
            try {
                final String base64image = imageData.replace("data:image/png;base64,", "");
                final byte[] decodedString = Base64.decode(base64image, Base64.DEFAULT);
                final Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                this.saveToInternalStorage(decodedByte);

                final Bundle data = new Bundle();
                data.putBoolean("isSuccess", true);
                session.sendEvent(SessionEvent.SELFIE_VALIDATION_RESULT, data);

            } catch (IOException ioe) {
                Log.v("DemoActivity", "Error processing image", ioe);

                final Bundle data = new Bundle();
                data.putBoolean("isSuccess", false);

                session.sendEvent(SessionEvent.SELFIE_VALIDATION_RESULT, data);
            }
        } else {
            final Bundle data = new Bundle();
            data.putBoolean("isSuccess", true);
            session.sendEvent(SessionEvent.SELFIE_VALIDATION_RESULT, data);
        }
    }

    private void saveToInternalStorage(Bitmap bitmapImage) throws IOException {
        final long tsLong = System.currentTimeMillis() / 1000;
        final String ts = String.valueOf(tsLong);
        final String fileName = "selfie_" + ts + ".jpeg";

        final String filePath =  this.getGalleryPath(fileName);
        final File imageFile = new File(filePath);

        try (FileOutputStream fos = new FileOutputStream(imageFile)) {
            // Use the compress method on the BitMap object to write image to the OutputStream
            bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        }
    }

    private String getGalleryPath(String fileName) {
        return Environment.getExternalStorageDirectory() + File.separator
                + Environment.DIRECTORY_DCIM + File.separator + fileName;
    }
}

Every event has name and optional data attributes that contain all details about the event itself.

6 . Start the session itself

session.start(ENV_HOST, user, assignment, new JSONObject());

ENV_HOST here is the host where the call should be started (https://dev.eazyshow.com, https://demo.eazyshow.com, etc.) user and assignment are objects initialised in item #3 new JSONObject() is an optional parameters to start the session, these can be used to pass additional details on session start.

Application Permissions

Eazyshow functionality requires this set of permissions in manifest.xml:

    <uses-feature android:name="android.hardware.camera2.full" />
    <uses-feature android:name="android.hardware.camera" android:required="true"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="true" />
    <uses-feature android:name="android.hardware.audio.output" android:required="true" />
    <uses-feature android:name="android.hardware.microphone" android:required="true" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
    <uses-permission android:name="android.permission.ACCESS_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_LOCATION_EXTRA_COMMANDS" />
Let's talk
Please fill out the form below and we will be in touch with you within one business day