All Products
Search
Document Center

Mobile Platform as a Service:Android API

Last Updated:Jul 11, 2022

Important: Since June 28, 2020, mPaaS has stopped support for the baseline 10.1.32. Please use 10.1.68 or 10.1.60 instead. For how to upgrade the baseline from version 10.1.32 to 10.1.68 or 10.1.60, see mPaaS 10.1.68 upgrade guide or mPaaS 10.1.60 upgrade guide.

In baseline 10.1.32 or later versions, the MPSync class in the mPaaS middle layer encapsulates all APIs of the Mobile Sync Service (MSS). You can use the MPSync object to implement all functions of MSS.

java.lang.Object
  - com.mpaas.mss.adapter.api.MPSync

Related public functions are shown as follows:

Return value type

Methods and description

void

setup(Application application)

Initializes basic services on which MSS depends. Call this API before you call the initialize method. This function is available only in baseline 10.1.60 and later versions.

void

appToBackground()

Notifies the client SDK that the App has been switched to the background and it needs to disconnect from the server. Call this function every time the App is switched to the background.

void

appToForeground()

Notifies the client SDK that the App has been switched to the foreground and it needs to connect to the server. Call this function every time the App is switched to the foreground.

void

clearUserInfo()

Clears user information when a user logs out.

void

initialize(Context context)

Initializes MSS.

boolean

isConnected()

Checks whether MSS is running properly.

void

registerBiz(String bizType, ISyncCallback syncCallback)

Registers a callback to receive business data. If this API is called, the client SDK will call the syncCallback class after receiving synchronized data.

void

reportMsgReceived(SyncMessage syncMessag)

Notifies MSS of the data synchronization success after data is received in the syncCallback class. Before receiving reportMsgReceived, MSS attempts to resend the data for a maximum of six times. If all resending attempts fail, the data is permanently deleted.

void

unregisterBiz(String bizType)

Unregisters a specified synchronization configuration. If this API is called, the client SDK will not call the syncCallback class when receiving synchronized data.

boolean

updateUserInfo(String sessionId)

Call this API at least once when the login information (userId or sessionId) is modified.

setup(Application application)

Declaration

public static void setup(Application application)

Description

Used to initialize the base service that MSS depends on. This function needs to be called before the initialize method is called. This function is available only in baseline 10.1.60 and later versions.

Parameters

Parameter

Type

Description

application

Application

An application instance.

Returned value

None.

appToBackground()

Declaration

public static void appToBackground()

Description

Notifies the client SDK that the App has been switched to the background and it needs to disconnect from the server. Call this function every time the App is switched to the background.

We recommend that you call this API inside the onStop() method of the home page. If this API is not called when the App is switched to the background, the network connection between the App and the server cannot be released in a timely manner, increasing power consumption and traffic usage.

Parameters

None.

Returned value

None.

appToForeground()

Declaration

public static void appToForeground()

Description

Notifies the client SDK that the App has been switched to the foreground and it needs to connect to the server. Call this function every time the App is switched to the foreground.

We recommend that you call this API inside the onResume() method of the home page.

Parameters

None.

Returned value

None.

clearUserInfo()

Declaration

public static void clearUserInfo()

Description

Clears user information when a user logs off.

Parameters

None.

Returned value

None.

initialize(Context context)

Declaration

public static void initialize(Context ctx)

Description

You can call this API to initialize MSS. Your App can use MSS only after you call this API.

During the life cycle of the App (from the time the App is started to the time the App is stopped), this API needs to be called only once.

Parameters

Parameter

Type

Description

ctx

Context

A non-empty Context.

Returned value

None.

isConnected()

Declaration

public static boolean isConnected()

Description

Checks whether MSS is running properly.

Parameters

None.

Returned value

Returns true if the service is normal, and returns false if the service is abnormal.

registerBiz(String bizType, ISyncCallback syncCallback)

Declaration

public static void registerBiz(String biz, ISyncCallback callback)

Description

Used to register a callback for receiving service data. If this API is called, the client SDK will call the syncCallback class after receiving synchronized data.

This API needs to be called once for each synchronization configuration.

Parameters

Parameter

Type

Description

bizType

String

Synchronization identifier

syncCallback

ISyncCallback

Callback implementation class

Returned value

None.

reportMsgReceived(SyncMessage syncMessag)

Declaration

public static void reportMsgReceived(SyncMessage msg)

Description

After the synchronously pushed data is received in syncCallback, call this API to notify MSS that the synchronized data has been received successfully. Before receiving the reportMsgReceived, MSS attempts to resend the data for a maximum of six times. If all resending attempts fail, the data will be permanently deleted.

Parameters

Parameter

Type

Description

syncMessag

SyncMessage

Message synchronization

Returned value

None.

unregisterBiz(String bizType)

Declaration

public static void unregisterBiz(String biz)

Description

Unregisters a specified synchronization configuration. MSS will not call syncCallback after MSS receives the synchronization configuration data.

Parameters

Parameter

Type

Description

biz

String

Synchronization identifier

Returned value

None.

updateUserInfo(String sessionId)

Declaration

public static boolean updateUserInfo(String sessionId)

Description

Calling inside the method is based on the LongLinkSyncService.getInstance().updateUserInfo(String userId, String sessionId) API, in which userId indicates the user ID specified in MPLogger.This API is called when userId or sessionId changes and will update user login information.

Both parameters are required for logon. If userId is not specified, this method returns false, indicating a calling failure.

This method must be called upon session expiration or each successful automatic logon. Note that the automatic logon function is enabled after a user logs on to the client once. The general calling principle is that this method must be called when userId or sessionId changes.

Parameters

Parameter

Type

Description

sessionId

String

Session ID.

Returned value

Returns true if the user information is updated successfully, and returns false if userId is not set at logon.