Skip to content

HTTP Request Customization in Android

For Android, you can specify the NetworkInterceptorListener listener which provides you with a callback that receives HttpURLConnection right before they are fired.

If you want to intercept HTTP requests, make sure to specify the listener before startLiveness or matchFaces:

private val authorization = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs"

private val networkInterceptorListener: NetworkInterceptorListener =
    NetworkInterceptorListener() { httpURLConnection: HttpURLConnection ->
        httpURLConnection.setRequestProperty("Authorization", authorization)
}

FaceSDK.Instance().setNetworkInterceptorListener(networkInterceptorListener)
Face.Instance().startLiveness(this@MainActivity) { livenessResponse: LivenessResponse? -> }
private String authorization = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmYWNlLXNkayI6IkhhdmUgYSBncmVhdCBkYXkhIn0.IPoW0D0LnMv_pL4U22MuIhDNGIdK34TaHhqhKBAaBEs";

private NetworkInterceptorListener networkInterceptorListener = new NetworkInterceptorListener() {
    @Override
    public void onPrepareRequest(HttpURLConnection httpURLConnection) {
        httpURLConnection.setRequestProperty("Authorization", authorization);
    }
};


FaceSDK.Instance().setNetworkInterceptorListener(networkInterceptorListener);
Face.Instance().startLiveness(MainActivity.this, livenessResponse -> {});