LogoSignature Service
SmartContract SDKAndroid SDK

Getting started

The SmartContract SDK has to be configured and initialized prior using any provided service.

SmartContract.configuration().setSecServerUrl(new URL("https://example.com/sense/appserver/Server"));
SmartContract.configuration().setLicense("myLicense");
SmartContract.configuration().setWorkflowEngineUrl(...); // optional
SessionService sessionService = SmartContract.initialize(this);

The SessionService instance received provides all the services needed to create a session with the server.

Opening a session

The first time a session is opened, the user must be enrolled to the server with a password and an enrollment code. Following sessions can then be opened with the password only.

List<String> enrolledUsers = sessionService.getEnrolledUsers();
if(enrolledUsers.isEmpty()) {
  sessionService.enrollApplication(username, password, enrollmentCode, sessionEstablishmentListener);
} else {
  sessionService.openApplicationSession(username, password, sessionEstablishmentListener);
}

This method is asynchronous and can be safely used from the UI thread. The SessionEstablishmentListener listener given as parameter will be notified of the result of the request.

public class MyListener implements SessionEstablishmentListener {
  public void onLoginSuccessful(Services services) {
    Log.i("MyApp", "Session opened");
  }
  public void void onLoginFailed(Throwable cause) {
    Log.e("MyApp", "Login failed", cause);
  }
  public onUpdateAvailable(String downloadUrl) {
    Log.i("MyApp", "An update is available");
  }
  public onApplicationUpToDate(String downloadUrl) {
    Log.i("MyApp", "Application is up-to-date");
  }
}

The session is now correctly opened and the Services provided can be used until the end of the session. It's recommended to register a SessionStatusListener to the session in order to be notified when the session has expired :

services.addSessionStatusListener(new SessionStatusListener() {
  @Override
  public void hasExpired() {
    // Close the app, reopen a new session, ...
  }
});

SmartContract API can be then used through the SmartContractService instance provided by the Services.

SmartContractService service = services.getSmartContractService();
// Load pending contracts
List<Contract> pendingContracts = service.getPendingContracts();
// Load contract's payload
Contract contract = pendingContracts.get(0);
byte[] payload = service.getPayload(contract.getId());
contract.setPayload(payload);
// Send contract's response with signature of the original payload.
service.sendResponse(contract.getId(), contract.getPayload(), "accepted", false);
// Send contract's response with signature of a custom payload (e.g a PDF file that has been edited)
byte[] customData = getCustomData();
service.sendResponse(contract.getId(), customData, "accepted", true);

Once the SDK doesn't need to be used anymore (e.g closing app), it's recommended to close it correctly using the SmartContract.terminate() method. This method closes properly the potentially existing user session and releases also some resources. The SDK will need to be initialized again to be accessible again.

SmartContract.terminate();

On this page