This topic describes how to integrate the MSS component with an Android client.
|
Note
As of June 28, 2020, mPaaS no longer maintains the 10.1.32 baseline. Use the 10.1.68 or 10.1.60 baseline. To upgrade your baseline version, see mPaaS 10.1.68 Upgrade Guide or mPaaS 10.1.60 Upgrade Guide. |
The MSS component supports two integration methods: native AAR-based integration and component-based integration.
Integration involves two steps:
Prerequisites
You have integrated your project with mPaaS.
-
For native AAR-based integration, add mPaaS to your project.
-
For component-based integration, complete the component-based integration process.
Add the SDK
Native AAR-based integration
Use Component Management (AAR) to install the SYNC component in your project. For more information, see AAR component management.
Component-based integration
In the Portal and Bundle projects, use Component Management to install the SYNC component.
For more information, see Manage component dependencies > Add or remove component dependencies.
Use the SDK
In baselines 10.1.32 and later, the MPSync class in the mPaaS middleware layer encapsulates all MSS APIs. Use the MPSync object to access all MSS features.
The following table lists the MSS APIs. For details, see Android API reference.
|
API |
Description |
|
setup(Application application) |
Initializes the basic services that MSS depends on. Must be called before |
|
initialize(Context context) |
Initializes the API and the MSS service. |
|
appToForeground() |
Notifies the client SDK that the app is started to establish a network connection with the server. Call this method each time the app is brought to the foreground. |
|
appToBackground() |
Notifies the client SDK that the app is sent to the background to disconnect from the server. Call this method each time the app is sent to the background. |
|
updateUserInfo(String sessionId) |
Updates logon information when userId or sessionId changes. Must be called at least once. |
|
clearUserInfo() |
Logs out the user. |
|
registerBiz(String bizType, ISyncCallback syncCallback) |
Registers a |
|
unregisterBiz(String bizType) |
Unregisters the specified synchronization configuration. After unregistration, the SDK no longer invokes the |
|
reportMsgReceived(SyncMessage syncMessag) |
Acknowledges receipt of data from the |
|
isConnected() |
Checks whether the MSS service is running as expected. |
Code sample
This sample uses the SDK of baseline 10.1.32. A button obtains the device ID when tapped, and the console uses that ID to push synchronization data to the device. The synchronization identity is bizType.
This sample demonstrates basic MSS API calls and is not a best practice. Download the best practice code from the Get code sample page.
public void button1Clicked(View view)
{
// Use the getUtdid method to obtain the device ID.
String utdid =UTDevice.getUtdid(MainActivity.this);
// Print the MSS data in Logcat.
Log.e("=========",utdid);
// Initialize the API and the MSS service.
MPSync.initialize(MainActivity.this);
// Register a callback to receive business data. After the pushed data is received, the syncCallback is called.
MPSync.registerBiz("bizType",new SyncCallBackImpl());
// Establish a network connection with the server.
MPSync.appToForeground();
}
public class SyncCallBackImpl implements ISyncCallback
{
@Override
public void onReceiveMessage(SyncMessage syncMessage) {
// Print the MSS data in Logcat.
Log.e("=========",syncMessage.msgData);
// Notify the MSS server that the data is successfully received.
MPSync.reportMsgReceived(syncMessage);
}
}
TLS support
To enable TLS connections on ports other than 443, add the metadata mss_use_tls to the manifest file and set its value to YES.

Connections on port 443 use TLS by default.