developer portal

Documentation

edgeSDK Android Wrapper

This guide serves as a main documentation that you will need to learn how to use and integrate edgeSDK app wrappers into your Android project.

Main Packages

  • edgeSDK-android-app-ops wrapper : Interfaces to control the edge service life cycle and microservice functionality.
  • edgeSDK-android-app-auth wrapper : Interfaces that assist with associating the edge service to a user.

Note: For edgeSDK integration on Android, user needs to install mimik edge service from Google Play Store; the developer can choose to prompt a redirection to Google Play Store if edgeSDK is not detected upon starting the application.

Hint: There is an edgeSDK detection function under edgeSDK-android-app-ops wrapper.

Wrapper Installation

  1. Open your project, under build.gradle add the following:
allprojects {
  repositories {
    maven {
      url "https://s3-us-west-2.amazonaws.com/mimik-android-repo"
    }
  }
}
  1. Next, add the following dependencies to your app build.gradle:
dependencies {
  implementation 'com.mimik.edgesdk-android-client:edgeappops:0.1.16'
  implementation 'com.mimik.edgesdk-android-client:edgeappauth:0.1.12'
}
  1. Finally, add the mimik authorization handler activity to the application object in AndroidManifest.xml
<activity android:name="com.mimik.edgeappauth.appauth.HandleAuthorizationActivity">
  <intent-filter>
    <action android:name="com.mimik.edgeappauth.appauth.HANDLE_AUTHORIZATION_RESPONSE_EDGE"/>
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
</activity>

Android App Ops Wrapper

This wrapper has the following usages:

  • Wrapper initialization
  • Check edgeSDK availability
  • Start edgeSDK
  • Stop edgeSDK
  • Get edgeSDK Info
  • Report device location
  • Deploy microservice
  • Remove microservice
  • Microservice configuration

Wrapper initialization

Description

Creates an EdgeAppOps object. The getApplicationContext parameter is the application context, while the EdgeConfig parameter contains the port which the edge service should attach to.

Example Code

EdgeConfig edgeConfig = new EdgeConfig(9999);
EdgeAppOps opsWrapper = new EdgeAppOps(getApplicationContext(), edgeConfig);

Check edgeSDK availability

Description

Returns true if the Android OS package manager detects the edge service (com.mimik.edgeservice) is enabled.

Example Code

boolean edgeInstalled = opsWrapper.isPackageInstalled();

Start edgeSDK

Description

Initializes and starts the edge service. Returns true if the service has been successfully started, or false otherwise.

Example Code

boolean edgeStarted = opsWrapper.startEdge();

Stop edgeSDK

Description

Attempts to stop the edge service if it has been started. The opsWrapper instance must be the same as the instance used to start edge, or this function will do nothing.

Example Code

opsWrapper.stopEdge();

Get edgeSDK info

Description

Request information about the edge service that is running on the device.

Example Code

Intent postInfoIntent = new Intent(getApplicationContext(), SomeActivity.class);
postInfoIntent.setAction(SOME_ACTION);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), SOME_REQUEST_CODE, postInfoIntent, 0);
opsWrapper.getInfo(pendingCompletionIntent);

/*
The PendingIntent parameter defines an intent for the wrapper to send once the information is ready. 
Request status will be provided as an extra string in the intent, which can be parsed using the following code:
*/

protected void onNewIntent(Intent intent) {
  if (intent.getAction() != null && intent.getAction().equals(SOME_ACTION)) { // Detect if intent is the one that was passed in getInfo()
    EdgeRequestStatus<EdgeInfoResponse> status = EdgeRequestStatus.fromIntent(intent, EdgeInfoResponse.class);
    if (status.response != null) {
      Log.d(TAG, status.response.toJson()); // Success case
    } else {
      Log.d(TAG, status.error.getErrorMessage()); // Failure case
    }
  }
}

/*
The response object contains the following members:
*/

EdgeInfoResponse response = status.response;
String accountId = response.getAccountId(); // The currently associated account's accountId
String name = response.getName(); // The name of the device determined by the edge service
String nodeId = response.getNodeId(); // The nodeId of the edge service instance
String version = response.getVersion(); // The version of the edge service

Report device location

Description

Reports a location for the edge service to log. This location will be used for proximity functionality with other edge service nodes. The String parameter accessToken is a valid accessToken for the account associated with the edge service. The Location parameter is a standard Android Location object (android.location.Location). The PendingIntent parameter defines an intent for the wrapper to send once the information is ready.

Example Code

opsWrapper.reportLocation(accessToken, location, pendingCompletionIntent);

microservice configuration

Description

Configure the microservice before deployment.

Example Code

MicroserviceDeploymentConfig config = new MicroserviceDeploymentConfig();
config.setName("example"); // Name of the microservice
config.setFilename("example.tar"); // Filename of the microservice image
config.setResourceStream(getResources().openRawResource(R.raw.example)); // ResourceStream of the microservice image file
config.setApiRootUri(Uri.parse("/example")); // Endpoint at which the microservice will be accessible
Map<String, String> env = new HashMap<>();
env.put("test_variable", "Hello world!");
config.setEnvVariables(env); // Map of environment variables made available to the microservice

Deploy microservice

Description

Deploys a microservice to the mimik container manager. Deploying a microservice makes it accessible at the endpoint specified in the configuration.

Example Code

MicroserviceDeploymentStatus status = opsWrapper.deployEdgeMicroservice(accessToken, microserviceConfig);

Remove microservice

Description

Remove a microservice from the mimik container manager. Removing a microservice makes it inaccessible and clears any configuration. The removed microservice is determined by the name field of the configuration object.

Example Code

MicroserviceDeploymentStatus status = opsWrapper.removeEdgeMicroservice(accessToken, microserviceConfig);

Android App Auth Wrapper

This wrapper has the following usages:

  • edgeSDK authorization
  • edgeSDK unauthorization

edgeSDK authorization

Description

Acquire information from the running edge service, request an access token from the mimik login server, and associate the edge service with the account.

Example Code

AuthConfig authConfig = new AuthConfig();
authConfig.setClientId(CLIENT_ID); // ClientId provided by mimik developer portal
authConfig.setRedirectUri(REDIRECT_URI); // RedirectUri specified by the developer when registering with the mimik developer portal
List<String> additionalScopes = new ArrayList<String>();
additionalScopes.add(SCOPE_GPS);
authConfig.setAdditionalScopes(additionalScopes); // Additional scopes which provide permission to used certain functionality
authConfig.setAuthorizationRootUri(BuildConfig.MID_URI); // Root url of the mimik login server

Intent postInfoIntent = new Intent(getApplicationContext(), SomeActivity.class);
postInfoIntent.setAction(AUTHORIZATION_ACTION);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), SOME_REQUEST_CODE, postInfoIntent, 0);
EdgeAppAuth.authorize(getApplicationContext(), authConfig, pendingCompletionIntent);

/*
AuthConfig is a configuration object specifying the mimik login server that will be used. First, a query will be sent to the edge service to acquire
information on the instance. This information, will be passed to the login server, along with prompting the user to log in within a CustomTab.
If the user logs in and allows access, the edge service will be associated with the user’s account. The access token, along with relevant OpenID
information, will be returned as an extra field added to the intent defined in the PendingIntent, which can be parsed using the following:
*/

protected void onNewIntent(Intent intent) {
  if (intent.getAction() != null && intent.getAction().equals(AUTHORIZATION_ACTION)) { // Detect if intent is the one that was passed in authorize()
    EdgeRequestStatus<AuthResponse> status = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
    if (status.response != null) {
      Log.d(TAG, status.response.getAccessToken()); // Success case
    } else {
      Log.d(TAG, status.error.getErrorMessage()); // Failure case
    }
  }
}

edgeSDK unauthorization

Description

Acquire information from the running edge service, request an access token from the mimik login server, and unassociate
the edge service with the account.

Example Code

AuthConfig authConfig = new AuthConfig();
authConfig.setClientId(CLIENT_ID);
authConfig.setRedirectUri(REDIRECT_URI);
authConfig.setAuthorizationRootUri(MID_URI);

Intent postInfoIntent = new Intent(getApplicationContext(), SomeActivity.class);
postInfoIntent.setAction(UNAUTHORIZATION_ACTION);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), SOME_REQUEST_CODE, postInfoIntent, 0);
EdgeAppAuth.unauthorize(getApplicationContext, authConfig, pendingCompletionIntent);

/*
This process follows the same procedure as authorization, except it disassociates the
edge service with the user account.
*/

protected void onNewIntent(Intent intent) {
  if (intent.getAction() != null && intent.getAction().equals(UNAUTHORIZATION_ACTION)) { // Detect if intent is the one that was passed in authorize()
    EdgeRequestStatus<AuthResponse> status = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
    if (status.response != null) {
      Log.d(TAG, status.response.getAccessToken()); // Success case
    } else {
      Log.d(TAG, status.error.getErrorMessage()); // Failure case
    }
  }
}

Need more help?

Feel free to contact us on stack overflow or send us a question via our support page if you have any questions.

Was this page helpful?