SDK for Android Developer's Guide

Proxy usage

The developer can use a proxy server for all HTTP connections that are done in the SDK.

NetworkProxy class

NetworkProxy class is used to setup proxy server settings. You need to specify host name, port number and credentials (if required) to use proxy.

There are two ways to enable proxy:

  1. Before MapEngine initialization:
  2. After MapEngine initialization:


By default, proxy authentication in the SDK is implemented using global Java Authenticator.setDefault(...) API. It might be inefficient if only SDK HTTP requests should be authenticated, or HTTP requests should include an authentication header upfront(aka preemptive authentication). For such cases, a developer can enable using OkHttp by the SDK, as this library handles it natively out-of-the-box.

To use proxy with OkHttp add the following code:
Here you can find an example of implementation:
String hostname = "hostName";
// Can be any in range from 0 to 65535
int port = 3636;

Credentials credentials = new Credentials("username", "password");
NetworkProxy networkProxy = new NetworkProxy(hostname, port, credentials);

// OkHttp should be included as a dependency for the app (e.g. in the app/build.gradle file).
// OkHttp version 4.* is officially supported, although SDK should work with 3.* as well as with 5.* versions.
// Add the code below if you want to use proxy with OkHttp

// Choose one of the options above to enable proxy

// First option

// Second option