Skip to main content

MTE Relay Client for Android

The MTE Relay Client for Android package facilitates encrypted communication between an Android application and an MTE Relay Server running in AWS.

Installation

The Android Java package is available as a Maven dependency.

Alternatively, you can add a 'libs' directory to the same level as the src directory in your app, then download the Relay library from our Github Repo and compile it. Add the resulting .aar to the libs dir you just created and add a new line with implementation files('libs/eclypses-aws-mte-relay-client-android-release-3.4.9-release.aar') to your module build.gradle dependencies block.

Quick Start Guide

In the class where you will maintain the Relay reference, create a class variable for the relay singleton.

private static Relay relay;

Then, in the constructor for that class, instantiate the Relay class by passing the context and a new instance of InstantiateRelayCallback.

relay = Relay.getInstance(ctx, new InstantiateRelayCallback() {
@Override
public void onError(String message) {
// handle instantiate errors appropriately
}

@Override
public void relayInstantiated() {
// any code to run after Relay is instantiated
}
});

Simple Volley GET and POST requests

When creating your Volley request, instead of adding your original server URL, add the URL of your MTE Relay Server.
Example: https://<RELAY_SERVER>.example.com/

Then call the relay.addToMteRequestQueue(request, headers, responseListener) method, passing the following parameters:

  • request
    • An instance of a request object.
  • headers
    • a String[] of the names of any http headers you wish to have protected by MTE
  • responseListener
    • An instance of a new RelayResponseListener()

Example:

String[] headersToEncrypt = new String[] {"Content-Length"};

relay.addToMteRequestQueue(request, headersToEncrypt, new RelayResponseListener() {
@Override
public void onError(String message, Map<String, List<String>> responseHeaders) {
// Handle errors appropriately and response headers as necessary
}

@Override
public void onResponse(byte[] responseBytes, Map<String, List<String>> responseHeaders) {
// Returns returns the response body as a byte[], and the response headers as a Map
}

@Override
public void onResponse(JSONObject responseJson, Map<String, List<String>> responseHeaders) {
// Returns returns the response body as a JSONObject, and the response headers as a Map
}
});

Examples:

Source Code: