Mason Docs

Fetching device metadata using the Mason Android SDK

Prerequisites

  1. Setup a new Android project
  2. Install the Mason Android SDK

Steps

  1. 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
        }
    });
    
  2. You should be able to 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());
                }
            });
        }
    });
    
  3. Disconnect from the Mason Platform before your activity is destroyed to prevent memory leaks

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