Skip to content

Tutorials 

Overview     Guides     Reference   Samples   Libraries

Integrate edgeEngine to Android - Java

Prerequisites

1. Install or update Android Studio to its latest version.

2. Set up your Android device to run your app during development.

Important: edgeEngine is not supported on emulators.

3. Install edgeEngine on your Android development device from the Google Play Store.

Important: For debugging purposes, you might want to download and install edgeEngine on your development computer (click here to download) as well.

Step 1. Register your project

1. Create your mimik developer account here or sign in to the mimik developer console, if you already have one.

Important: mimik developer account is required for application registration, platform authorization and microservice deployment.

2. In the mimik developer console, click Create New Project.

3. Enter a Project Name.

4. Upload a logo image if you want to use your own Project Logo.

5. Submit the form with the auto-generated Redirect URI or enter your own.

Important: edgeEngine uses OAuth 2.0 for authentication and a redirect URI is necessary for the process. The standard format of redirect URI is com.<string>://<string>. You can learn more about it here.

Step 2. Integrate edgeEngine to your application

EdgeMobileClient Android Wrapper
EdgeMobileClient

EdgeMobileClient is a wrapper library for interacting with the mimik edge service installation on an Android device. This guide provides instructions for integrating mimik edgeEngine functionality into your Android project.  

Gradle Usage

EdgeMobileClient is available as a gradle library.

Add the following repository to your project-level build.gradle.

allprojects {
    repositories {
        maven {
            url "https://s3-us-west-2.amazonaws.com/mimik-android-repo"
        }
    }
}

Declare the authorization callback registered with mimik developer portal in your module build.gradle.

android {
    defaultConfig {
        manifestPlaceholders = ["appAuthRedirectScheme": "com.mimik.exampleplayground"]
    }
}

Then add the dependency to your module build.gradle.

dependencies {
    api 'com.mimik.edgesdk-android-client:edgemobileclient:0.1.0'
}
Application Manifest

Add the EdgeMobileClient intent handler to the application-level AndroidManifest.xml to receive callbacks from mimik identity services

<manifest>
    <application>
        <activity android:name="com.mimik.edgemobileclient.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>
    </application>
</manifest>
Wrapper Features
  • Check for platform installation
  • Platform startup and shutdown
  • Platform authorization using mimik identity services
  • Microservice deployment and undeployment
  • List of deployed microservices
  • Platform instance information
  • Setting platform log levels
EdgeMobileClient Initialization

Initialize the EdgeMobileClient instance.

// EdgeConfig uses port 8083 by default
EdgeMobileClient edgeMobileClient = new EdgeMobileClient(getApplicationContext(), new EdgeConfig());

// Using a custom port 6699
EdgeMobileClient edgeMobileClient = new EdgeMobileClient(getApplicationContext(), new EdgeConfig(6699));
Platform Installation Check and Startup

Check if the mimik edge service is installed, and start it if available.

if (!edgeMobileClient.isPackageInstalled()) {
    // edge service is not installed
} else {
    if (edgeMobileClient.startEdge()) {
        // edge service was started and bound successfully
    }
}
Platform Shutdown

Unbind from the mimik edge service. This will not end the process if other applications are still using it.

edgeMobileClient.stopEdge();
Platform Authorization

Authorization of the mimik edge service using mimik identity services. A CustomTab is used to access the web portal, and callbacks are received as intents.

Send an authorization request.

final String APPAUTH_ENDPOINT = "https://mid.mimik360.com/";
final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String REDIRECT_URI = "{redirect uri registered with developer portal}";
final String MIMIK_LOGIN_ACTION = "some.intent.authorization.action";
final int REQUEST_CODE = 1234;

AuthConfig config = new AuthConfig();
config.setAuthorizationRootUri(Uri.parse(APPAUTH_ENDPOINT));
config.setClientId(APPAUTH_CLIENT_ID);
config.setRedirectUri(Uri.parse(REDIRECT_URI));
List<String> additionalScopes = new ArrayList<>();
additionalScopes.add("read:me");
config.setAdditionalScopes(additionalScopes);
Intent postAuthorizationIntent = new Intent(getContext(), this.getClass());
postAuthorizationIntent.setAction(MIMIK_LOGIN_ACTION);
postAuthorizationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), REQUEST_CODE, postAuthorizationIntent, 0);
edgeMobileClient.authorize(getApplicationContext(), config, pendingIntent);

Then handle the callback intent in your activity.

static final String MIMIK_LOGIN_ACTION = "some.intent.authorization.action";

@Override
public void onNewIntent(Intent intent) {
    if (MIMIK_LOGIN_ACTION.equals(intent.getAction())) {
        EdgeRequestStatus<AuthResponse> authRequestStatus
                = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
        if (authRequestStatus.error != null) {
            // There was an error with authentication
        } else {
            // Authentication was performed successfully
            String accessToken = authRequestStatus.response.getAccessToken();
        }
    }
}
Platform Unauthorization

Authorization of the mimik edge service using mimik identity services. A CustomTab is used to access the web portal, and callbacks are received as intents.

Send an authorization request.

final String APPAUTH_ENDPOINT = "https://mid.mimik360.com/";
final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String REDIRECT_URI = "{redirect uri registered with developer portal}";
final String MIMIK_UNAUTHORIZATION_ACTION = "some.intent.unauthorization.action";
final int REQUEST_CODE = 1234;

AuthConfig config = new AuthConfig();
config.setAuthorizationRootUri(Uri.parse(APPAUTH_ENDPOINT));
config.setClientId(APPAUTH_CLIENT_ID);
config.setRedirectUri(Uri.parse(REDIRECT_URI));
Intent postAuthorizationIntent = new Intent(this, this.getClass());
postAuthorizationIntent.setAction(MIMIK_UNAUTHORIZATION_ACTION);
postAuthorizationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), REQUEST_CODE, postAuthorizationIntent, 0);
edgeMobileClient.authorize(getApplicationContext(), config, pendingIntent);

Then handle the callback intent in your activity.

static final String MIMIK_UNAUTHORIZATION_ACTION= "some.intent.unauthorization.action";

@Override
public void onNewIntent(Intent intent) {
    if (MIMIK_UNAUTHORIZATION_ACTION.equals(intent.getAction())) {
        EdgeRequestStatus<AuthResponse> authRequestStatus
                = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
        if (authRequestStatus.error != null) {
            // There was an error with unauthorization
        } else {
            // Unauthorization was performed successfully
            String accessToken = authRequestStatus.response.getAccessToken();
        }
    }
}
Deploying Microservices

Microservice deployment requires an access token from the authorization stepSend an authorization request.

The following example uses an InputStream from a raw resource.

MicroserviceDeploymentConfig config = new MicroserviceDeploymentConfig();
config.setName("example-v1");
config.setFilename("example-v1.tar");
config.setResourceStream(getApplicationContext().getResources().openRawResource(R.raw.example_v1));
config.setApiRootUri(Uri.parse("/example/v1"));
Map<String, String> env = new HashMap<>();
env.put("MCM.WEBSOCKET_SUPPORT", "true");
env.put("uMDS", "http://127.0.0.1:8083/mds/v1");
config.setEnvVariables(env);

MicroserviceDeploymentStatus status = edgeMobileClient.deployEdgeMicroservice(accessToken, config);
if (status.error != null) {
    // There was an error deploying the microservice
} else {
    // The microservice was deployed successfully
}
Removing Microservices

Microservice removal requires an access token from the authorization step

MicroserviceDeploymentConfig config = new MicroserviceDeploymentConfig();
config.setName("example-v1");

MicroserviceDeploymentStatus status = edgeMobileClient.removeEdgeMicroservice(accessToken, config);
if (status.error != null) {
    // There was an error removing the microservice
} else {
    // The microservice was removed successfully
}
Listing Deployed Microservices

Listing deployed microservices requires an access token from the authorization step.

// List of microservice images uploaded to edge
List<MicroserviceImage> imageList = edgeMobileClient.getDeployedImages(accessToken);

// List of containerized microservice images running on edge
List<MicroserviceContainer> imageList = edgeMobileClient.getDeployedContainers(accessToken);
Platform Instance Information

Running information from the mimik edge platform. Information is received through an intent.

Send an information request.

final String ACTION_EDGEINFO = "some.intent.info.action";
final int REQUEST_CODE = 12345;

Intent postInfoIntent = new Intent(this, this.getClass());
postInfoIntent.setAction(ACTION_EDGEINFO);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), /*Arbitrary*/ REQUEST_CODE, postInfoIntent, 0);
mEdgeAppOps.getInfo(pendingIntent);

Then handle the callback intent in your activity.

final String ACTION_EDGEINFO = "some.intent.info.action";

@Override
public void onNewIntent(Intent intent) {
    if (ACTION_EDGEINFO.equals(intent.getAction())) {
        EdgeRequestStatus<EdgeInfoResponse> status = EdgeRequestStatus.fromIntent(intent, EdgeInfoResponse.class);
        if (status.error != null) {
            // There was an error getting the platform information
        } else {
            String nodeId = status.response.getNodeId();
        }
    }
}
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.

Your feedback is important to us ~