Fetching device metadata using the Mason Android SDK
Prerequisites
- Setup a new Android project
- Install the Mason Android SDK
Steps
-
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 } });
-
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()); } }); } });
-
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(); }