SDK integration

Add maven repository

In the settings.gradle add the following to repositories

maven {
    url "https://privately.jfrog.io/artifactory/margin-libs/"
}

Add SDK dependencies

Add the following to any module using the SDK

implementation 'privately-sdk:core:1.0.1'
implementation 'privately-sdk:age-estimation-image:1.0.1'

You're good to go!

Perform an age estimation

Setup the app's Manifest

The age estimation views require access to the camera and make use of the auto-focus feature from Android. The permissions need to be added to the app's Manifest to work properly.

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera" />

Make sure you have a set of API key and secret

If you haven't created an account yet, visit … to register for a free trial.

Create a view to handle age estimations

Create a layout file and add the VideoAgeEstimationView to it.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ch.privately.ageestimation.image.estimation.VideoAgeEstimationView
        android:id="@+id/video_age_estimation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Authenticate the core SDK

PrivatelyCore.INSTANCE.init(this);
if (!PrivatelyCore.INSTANCE.isAuthenticated()) {
    PrivatelyCore.INSTANCE.authenticate("API key", "secret key", new PrivatelyCore.AuthenticationCallback() {
        @Override
        public void onSuccess() {
            Log.e(TAG, "Authenticated successfully");
        }

        @Override
        public void onError(String error) {
            Log.e(TAG, "Error authenticating: " + error);
        }
    });
}

Register for age estimation callbacks and init the view

VideoAgeEstimationView ageEstimationView = findViewById(R.id.video_age_estimation_view);
AgeEstimationImageCore.registerAgeEstimationCallback(new AgeEstimationImageCallback() {
    @Override
    public void onVideoAgeEstimationResult(AgeEstimationImageResult ageEstimationImageResult) {
        Log.i(TAG, "Got estimate of " + ageEstimationImageResult.getAgeRange());
    }

    @Override
    public void onImageAgeEstimationResult(AgeEstimationImageResult ageEstimationImageResult) {

    }
});
ageEstimationView.initView(this);

The VideoAgeEstimationView handles the recording and estimation of age, the callback is executed when the estimation completes.