Mason Platform Android SDK

The Android SDK is designed to give your app access to the Mason Platform. This allows you to retreive information like device name, group, imei, serial, and more.

Releases

Mason Platform SDK AAR Javadoc Supported Mason OS Version(s)
mason-platform-android-0.2.0-release.aar javadoc-mason-platform-android-0.2.0.zip 2.2.0

Setup

Include the .aar file in the top-level libs directory of your project.

Modify both of your project’s gradle files:

build.gradle:

allprojects {
    repositories {
        // other repositories
        flatDir {
            dirs 'libs'
        }
    }
}

app/build.gradle:

compile(name: 'mason-platform-android-0.2.0.0-release', ext:'aar') // add the platform aar - NOTE: update the name to match included file
// NOTE: additional required dependencies
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

Usage/Sample: Fetch device name from Mason Platform

Initialize the connection to the Mason Platform

private MasonPlatform mPlatform;
// ...
// in OnCreate:
mPlatform = new MasonPlatform(this, new OnConnectListener() {
    @Override
    public void onConnected() {
        // Connection started
    }

    @Override
    public void onDisconnected() {
        // Connection stopped
    }
});

Fetch Device metadata (IMEI, name, tags, etc.) from the Mason Platform after the connection has been made

final Button deviceMetadataBtn = findViewById(R.id.device_data_btn);
deviceMetadataBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mPlatform.getDevice(new Callback<Device>() {
            @Override
            public void onResult(Device device) {
                Log.i(TAG, "Device name: " + device.getName());
            }

            @Override
            public void onError(Throwable throwable) {
                Log.e(TAG, throwable.toString());
            }
        });
    }
});

Disconnect from the Mason Platform before your activity is destroyed to prevent leaks

@Override
protected void onDestroy() {
    // Disconnect from the Platform
    if (mPlatform.isConnected()) {
        mPlatform.destroy(this);
    }
    super.onDestroy();
}