Contents
M800 SDK Android User Guide v. 141
Contents
Introduction
Glossary
How to Import the M800SDK
How to Configure the M800SDK
Step-by-step guide:
Sign-up Module
Introduction
Pre-requisites
How to implement sign-up
Sign up as a White Label User
Sign up as a SDK user
After a successful sign up
Connection Module
Introduction
Pre-requisites
How to implement
More on Connection Management
Contact Sync Module
Introduction
Pre-requisites
How to implement
Get M800 contact list
Get M800 native contact list
Start contact sync manually
Sync roster
Add M800 contact
Remove M800 contact
Register roster event listener
Find M800 contact by phone number.
Find M800 contact by JID
Presence (Last Seen)
Call Module
Introduction
How to implement
Making an outgoing on-net call (VOIP VOIP call)
To make an outgoing off-net call (VOIP PSTN call)
Receiving an incoming call
IM Push Notification
Remote Notification
To reject a call silently from an incoming call notification bundle
To handle a missed call notification
How to Configure M800ClientConfiguration
Steps to provide a comprehensive call experience
Support the mute and speaker feature
Play a sound locally to notify user the call is connected
Play a sound locally to notify user he/she has sent a DTMF (dual tone multi frequency) tone over the call
Dim screen when users face is close to the screen.
Work closely with network status.
Work closely with native phone status.
Responsive UI to the in-call events
Incoming call notifications.
Missed call notifications.
Call history management.
Use Third Party Push Service
IM Module
Introduction
Pre-requisites
How to Implement
Single User Chat Room(SUC)
Single User Chat Room(SUC) Creation
Monitor Single User Chat Room(SUC) Activity
Retrieve Single User Chat Room(SUC)
Single User Chat Room(SUC) Deletion
Retrieve Participants In Single User Chat Room(SUC)
Multi User Chat Room(MUC)
Introduction
The M800 SDK is a Java library for Android which enables developers to leverage M800's global voice and messaging platform.
The M800 SDK allows the developer to easily add voice and messaging functionality to an Android app, so that app users can make phone calls,
chat, retrieve contact lists, find users, and more.
This guide demonstrates the key APIs of the SDK. Previous development experience with Java and the Android platform is assumed.
Glossary
JID
A unique identifier for end users. JID stands for Jabber Identifier. For
example: +106565_demo01@demo.m800-api.com.
On-net call
Off-net call
PSTN
Add following dependencies for Phone Verification in your projects gradle file:
Production environment:
Testbed environment:
Note that the size of M800SDK library is large. If the total method count of the application reaches 64k, you will need enable in the your projects
gradle file:
Add following dependencies for M800SDK in your projects gradle file:
// Multidex library
compile com.android.support:multidex:1.0.1'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
}
}
Testbed environment:
<meta-data
android:name="com.m800.signup.server"
android:value="testbed"
tools:replace="android:value"/>
Include the following files if you have ProGuard enabled in your project:
proguardFile 'M800SDK-proguard-rules.pro'
proguardFile 'annotations.pro'
// Configure M800SDK
M800SDKConfiguration configuration = M800SDK.newConfiguration();
PreferenceUtil.fillInConfigurationWithPreference(configuration, this);
configuration.setCertificateFileForCall(mM800CertificateFile);
configuration.setCertificateFileForIM(mM800CertificateFile);
M800SDK.setConfiguration(configuration);
Step-by-step guide:
When using AndroidManifest.xml, copy the meta-data codes below into your AndroidManifest.xml.
Place your code values in the appropriate space; values represented here would of course be supplied by M800:
<meta-data
android:name="com.m800.application.key"
android:value="Your Application Key" />
<meta-data
android:name="com.m800.application.secret"
android:value="Your Application Secret" />
<meta-data
android:name="com.m800.application.identifier"
android:value="Your Application Identifier" />
<meta-data
android:name="com.m800.application.version"
android:value="1.0.0"/>
<meta-data
android:name="com.m800.carrier.name"
android:value="Your Carrier Identifier" />
<meta-data
android:name="com.m800.developer.key"
android:value="Your Developer Key" />
<meta-data
android:name="com.m800.developer.secret"
android:value="Your Developer Secret" />
<meta-data
android:name="com.m800.capabilities"
android:value="incoming,outgoing"/>
<meta-data
android:name="com.m800.expiration"
android:value="100000"/>
Prepare the M800Certificate File (mM800CertificateFile). In the demo app project, the source certificate file is named as cacert.crt and
placed in the /asset.
To see the full implementation, you should go to the ApplicationClass.java and look into the method :
Fill the keys, mentioned in Step 1, into the M800SDKConfiguration object. In the demo project, we used a helper class, PreferenceUtil, to
fill the keys. You may go to this class to reference the full implementation.
PreferenceUtil.fillInConfigurationWithPreference(configuration, this);
configuration.setCertificateFileForCall(mM800CertificateFile);
configuration.setCertificateFileForIM(mM800CertificateFile);
M800SDK.setConfiguration(configuration);
Note. You will need to set all of the following permissions in your manifest.xml file:
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE" />
android:name="android.permission.ACCESS_NETWORK_STATE" />
android:name="android.permission.READ_PHONE_STATE" />
android:name="android.permission.INTERNET" />
android:name="android.permission.RECORD_AUDIO" />
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
android:name="android.permission.GET_TASKS" />
android:name="android.permission.WAKE_LOCK" />
android:name="android.permission.BROADCAST_STICKY" />
android:name="android.permission.CHANGE_NETWORK_STATE" />
android:name="android.permission.CHANGE_WIFI_STATE" />
android:name="android.permission.READ_CONTACTS" />
You will need additional permissions for M800PhoneVerification SDK. Please refer to the corresponding user manual.
Sign-up Module
Introduction
The sign-up Module lets a 1st time user sign-up to the M800 server. A successful sign-up allows the end user to log in and out from the app in the
future.
Pre-requisites
Before sign-up, a user needs to be verified. Please consult the M800 Phone Verification SDKs user manual, for details on how to implement
phone verification. The M800 Phone Verification SDK is a separate product from the M800 SDK in this user guide.
M800SDK.getInstance().hasUserSignedUp()
If the method above returns false, user hasnt signed up, the sign up mechanism is crucial before connecting to M800SDK. Please
invoke M800SDK.getInstance().getManagement().signup(...) to start sign up.
/**
* Sign up user with your verified phone number, requestId and display name.
*
* @param phoneNumber
*
The phone number that to be registered. Numeric digits only.
* @param regionCode
*
The region code of user's region. 2-letters. For example, hk if the
user's region is Hong Kong.
* @param displayName
*
The display name of user.
* @param language
*
The {@link com.m800.sdk.IM800Management.M800Language} object. The
preferred language of this user. Language will be applied
*
in the push string.
* @param callback
*
The {@link M800ManagementCallback} interface to handle result of
operation.
*/
public void signup(final String displayName, final String phoneNumber, final String
regionCode, final String requestId, final M800Language language, final
M800ManagementCallback callback);
We also provide another API that can signup without verification request ID.
If the provided phone number is never registered before, the signup will be successful, but the user need to verify his/her phone number later
when he/she wants to use any paid functions of M800SDK like offnet call, SMS chat.
If the provided phone number is registered before and is signing up with the same device, the signup will be successful and the user will remain
her/his previous verification status.
If the provided phone number is registered before and user is switching device, the signup will be failed with error, indicating that the user need to
verify his/her phone number again.
To verify user's phone number, please use M800 Verification SDK and the signup API above.
/**
* Sign up user with your phone number.
*
*
* @param phoneNumber
*
The phone number that to be registered. Numeric digits only.
* @param regionCode
*
The region code of user's region. 2-letters. For example, 'hk' if the
user's region is Hong Kong.
* @param displayName
*
The display name of user, optional
* @param language
*
The {@link com.m800.sdk.IM800Management.M800Language} object. The
preferred language of this user. Language will be applied
*
in the push string.
* @param callback
*
The {@link M800ManagementCallback} interface to handle result of
operation.
*/
void signup(final String displayName, final String phoneNumber, final String
regionCode, final M800Language language, final M800ManagementCallback callback);
Take the demo project as an example, user verification information is saved as a VerificationInfo object. Please refer to the class Verificat
ionManager.java.
/**
* Sign up user with your network id and display name.
*
* @param sourceNetworkId
* The id of source network to be registered, {0-1, a-z} only.
* @param displayName
* The display name of source network.
* @param language
* The preferred language of this user. Language will be applied in the push string
* @param callback
* The interface to handle result of operation.
* @throws IllegalStateException
* sourceNetworkId is illegal that should be alphanumeric and the length is not
greater than the value defined by
* M800SDK_MaxSourceNetworkIdLength
*/
public void signup(String sourceNetworkId, String displayName, M800Language language,
M800ManagementCallback callback);
M800SDK.getInstance().getUsername();
After a successful sign up, You can get current users JID (M800 unique identifier) by the following API:
M800SDK.getInstance().getUserJID();
After a successful sign up, please connect to M800 server in order to use the M800SDK provided features. Connection details are
provided in the Connection section.
Connection Module
Introduction
The Connect Module allows the app to manage the connection to M800 servers. Specfically, the module lets the app perform the following:
Connect to M800 server.
Disconnect from M800 server.
Check connection status.
Go online.
Go offline.
Sign out current user.
Pre-requisites
Successful sign-up should have been completed before connecting to M800 servers.
How to implement
After signing up to the M800SDK, connection with M800 Server must be established before using the IM and Call features.
1. To check if the user has signed up, please follow Step 1 in the previous session (Sign Up to M800SDK).
2. To check the connection state, please invoke M800SDK.getInstance().getManagement().getConnectionState().
/**
* This enumeration contains states that represents connection status of
* Management module
*/
public static enum M800ManagementConnectionState {
M800ManagementConnectionDisconnected, /** < Disconnected */
M800ManagementConnectionConnecting, /** < Connecting */
M800ManagementConnectionConnected, /** < Connected */
}
/**
* Connect to management server with current user stored in system.
*
*/
public void connect();
4. Implement the IM800Management.M800ManagementConnectionListener interface to monitor the connectivity with M800SDK server.
/**
* This listener can receive events while connection is changed to connected or
disconnected
* @see com.m800.sdk.IM800Management.M800ManagementConnectionState
*/
public static interface M800ManagementConnectionListener {
/**
* Client is connected to M800 servers.
*/
public void onConnectedToM800();
/**
* Client is disconnected from M800 servers with error.
* If error is NotAuthorized, then need to kick user from system and signup new
user again.
* @param error The reason why is disconnected.
*
*/
public void onDisconnectedFromM800(M800Error error);
}
5. For the full implementation of connection management, please refer to the ApplicationClass.java in the demo project as an example.
Implement IM800Management.M800ManagementConnectionListener interface to monitor the connectivity:
M800SDK.getInstance().getManagement().addConnectionListener (this);
}
@Override
public void onConnectedToM800() {}
@Override
public void onDisconnectedFromM800(M800Error error) {
//Do disconnection handling
if
(M800SDK.getInstance().getManagement().needKickUserForError(error)){
kickUser(error);
}
}
}
/**
* Checks whether is the error to kick user out from app.
*
* @param error The given error from M800 callbacks.
* @return If true, means the user is invalid, need to kick user out.
* Otherwise if false, means the current user is still valid and can be continued to
use.
*/
public boolean needKickUserForError(M800Error error);
Every M800 contact has its unique JID (Jabber Identifier). JID is represented in two parts. The text before @ is the phone number with country
code prefix. The text after @ is the carrier name.
After contact sync is completed, if an M800 contact is a native contact, it can be searched by JID or phone number. If the M800Contact is not in
native phone book, it can only be searched by JID.
Pre-requisites
Successful sign-up and connection to M800 server.
How to implement
Get M800 contact list
class GetContactsTask extends AsyncTask<Void, Void, List<IM800Contact>> {
@Override
protected List<IM800Contact> doInBackground(Void... params) {
return M800SDK.getInstance().getContactManager().getM800Contacts();
}
@Override
protected void onPostExecute(List<IM800Contact> contacts) {
// Update UI
}
}
M800SDK.getInstance().getContactManager().startSyncNativeAddressBook(boolean
fullSync);
There is a limitation of how frequent M800 SDK can do contact sync, the default value is 1 minute. You can change this value.
Note. Dont set this value too low, contact sync is very memory and network bandwidth consuming.
M800SDK.getInstance().getContactManager().setMinimumContactSyncTimeInterval(millis);
M800SDK.getInstance().getContactManager().isNativeAddressBookSyncInProgress();
Sync roster
You can sync roster without sync native contacts.
M800SDK.getInstance().getContactManager().queryM800ContactRoster();
M800SDK.getInstance().getContactManager().removeM800Contact(<JID>);
To listener to the roster activities and push events, implement the following listener:
M800SDK.getInstance().getContactManager().addContactChangeListener(this);
M800SDK.getInstance().getContactManager().removeContactChangeListener(this);
@Override
public void onQueryRosterStart() {
// Called when SDK starts to query roster
}
@Override
public void onContactSyncCompleted(boolean hasChange) {
// Called when SDK receives roster push or roster query response
}
@Override
public void onContactSyncError(IM800ContactManager.Error error) {
// Called when error happens during contact sync
}
@Override
public void onNewAddContactRequest(M800AddContactRequest request) {
// Called when SDK receives a new add contact request
}
@Override
public void onAddContactRequestComplete(String jid, M800AddContactRequest.Direction
direction, boolean isAccepted) {
// Called when an add contact request is being accepted/declined/cancelled
}
M800SDK.getInstance().getContactManager().findM800ContactByPhoneNumber(phone#);
M800 server will also push current users contact presence information, to listen to the presence changes:
M800SDK.getInstance().getContactManager().addUserPresenceListener(new
IM800ContactManager.UserPresenceListener() {
@Override
public void onPresenceChanged(String JID, IM800ContactManager.UserPresence
presence) {
}
});
Call Module
Introduction
M800SDK provides functionality to initiate and handle calls.
There are three major models which facilities the call feature: M800Client, M800ClientConfiguration and M800Call.
M800Client manages the call engine of M800SDK, creates and preserve call objects from the initialization of user action or incoming call
bundles. It provides APIs for the application to listen for the call engine status via M800ClientDelegate listener.
To get the M800Client singleton from M800SDK, please invoke
M800SDK.getInstance().getRealtimeClient().
M800ClientConfiguration configures the call engine setting. For example, it configures the threshold of packet loss, the ring-back tone
and the hold tone.
M800SDK creates a default M800ClientConfiguration configuration for M800Client during SDK initialization. To get the current M800ClientC
onfiguration setting from M800Client, please invoke M800SDK.getInstance().getRealtimeClient().getCurrentConfiguration().
Developer may provide the customized M800ClientConfiguration configuration to M800Client and restart it, see M800Client.start(M800Clien
tConfiguration configuration):
/**
* Starts client with a new configuration.
* @param configuration
* A new configuration contains username, password, resources and so on.
*/
void start(M800ClientConfiguration configuration);
M800Call represents a VOIP call managed by M800Client. It provides information of a call. It manages the in-call activities of a call. For
example, it provides APIs to answer if it is an incoming call and to terminate the call.
M800Call also updates the application the call status and events. To listen for the status of a M800Call object. See
/**
* Adds delegate to handle evens of this call session.
* @param delegate To listener to call event.
*/
void addCallDelegate(M800CallDelegate delegate);
To understand more about the call module, the best way is to look into the class description, Java Documentation, on the package
com.m800.msme.api.
How to implement
In this section, we are going to descript the step-by-step procedure for how to use the main features provided by M800 call engine.
Please check the Java Documentation for the full description of input parameters. And refer to com.m800.uimenu.RealtimeMenuActivity
from the demo project for solid implementation.
/**
* Makes a call to given receiver which maybe phone number or user id.
* If receiver is a phone number, it is an offnet call.
* If receiver is user id (JID), it is an onnet call.
* @param username e.g. "+85288888888", the phone number or the username of JID
* @param carrier e.g. "maaii.com", the carrier of JID. i.e. existence of {@code
carrier} determines this is a Off-net call.
* @param display the encode display name with Base64 of user (the caller). This is
sent to the receiver as part of the incoming call notification information.
* @param userInfo Put caller extra info. e.g. name, social info, etc.
* @param callID A random id used to distinguish the {@link M800Call} object.
* @return A {@link M800OutgoingCall} made by the information provided.
*/
@Nullable
M800OutgoingCall createCall(String username, String display, String carrier,
Map<String, String> userInfo,
String callID);
call.dial();
/**
* Event: call is talking.
* @param call The call.
*/
void callBeginTalking(M800Call call);
The event indicates the call has started and you are talking with the callee.
After a certain period, you will receive a callTerminated event when the call ends. The termination would be triggered by either the callees
or your action to stop the call, the network failure or some other failure reasons.
/**
* Event: call is ended for some reasons.
* @param call The call.
*/
void callTerminated(M800Call call, int status, Map<String,String>
userInfo);
Otherwise, if the callee rejects your call, you will receive the callTerminated event from M800CallDelegate directly.
Get the M800Client instance from M800SDK.
See com.m800.uimenu.RealtimeMenuActivity from the demo project.
Please check the Java Documentation for the full description of input parameters. And refer to com.m800.uimenu.RealtimeMenuActivity
from the demo project for solid implementation.
/**
* Makes a call to given receiver which maybe phone number or user id.
* If receiver is a phone number, it is an offnet call.
* If receiver is user id (JID), it is an onnet call.
* @param username e.g. "+85288888888", the phone number or the username of JID
* @param carrier e.g. "maaii.com", the carrier of JID. i.e. existence of {@code
carrier} determines this is a Off-net call.
* @param display the encode display name with Base64 of user (the caller). This is
sent to the receiver as part of the incoming call notification information.
* @param userInfo Put caller extra info. e.g. name, social info, etc.
* @param callID A random id used to distinguish the {@link M800Call} object.
* @return A {@link M800OutgoingCall} made by the information provided.
*/
@Nullable
M800OutgoingCall createCall(String username, String display, String carrier,
Map<String, String> userInfo,
String callID);
call.dial();
Add listener M800CallDelegate to the outgoing call object. See com.m800.phonecall.CallScreenActivity from the demo project
/**
* Event: call is talking.
* @param call The call.
*/
void callBeginTalking(M800Call call);
The event indicates the call has started and you are talking with the callee.
After a certain period, you will receive a callTerminated event when the call ends. The termination would be triggered by either the callees
or your action to stop the call, the network failure or some other failure reasons.
/**
* Event: call is ended for some reasons.
* @param call The call.
*/
void callTerminated(M800Call call, int status, Map<String,String> userInfo);
Otherwise, if the callee rejects your call, you will receive the callTerminated event from M800CallDelegate directly.
/**
* Event: call is ended for some reasons.
* @param call The call.
*/
void callTerminated(M800Call call, int status, Map<String,String> userInfo);
IM Push Notification
The bundle is received internally via M800SDK connection module. It is broadcasted to the application level once it is received.
To listen for the IM Push Notifications for call, please register a BroadcastReceiver for the IntentFilter
M800CallNotification.getIntentFilterForM800CallNotifications(Context).
Please see com.m800.service.AppM800Service as an example:
@Override
public void onCreate() {
super.onCreate();
BroadcastReceiver mCallNotificationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Implement your own code
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(mCallNotificationReceiver,
M800CallNotification.getIntentFilterForM800CallNotifications(this));
}
Remote Notification
Received and configured by the application. For example, the incoming call notification will be received as GCM. Developer should
configure and implement the GCM service on application level.
To handle the incoming call notification bundles:
When incoming call notification bundle is received from Step 1, please provide it to the M800Client instance by invoking M800Client.catch
RemoteNotification(bundle). You may look into com.m800.service.GcmIntentService for reference.
/**
* Handle M800 Call notifications from GCM or M800 Push Service
* @param intent
*/
public static void onHandleCallNotification(Context context, Intent intent){
Bundle bundle = intent.getExtras();
M800Client client = M800SDK.getInstance().getRealtimeClient();
if (client != null) {
// Handle incoming push call
M800IncomingCall call = client.catchRemoteNotification(bundle);
if (null != call) {
//Start call UI
}
}
}
With the returned M800IncomingCall object from M800IncomingCall call = client.catchRemoteNotification(bundle);, application may now work
with the incoming call.
Present your own UI to work with the incoming call. For example, provide a button on screen for call answering and provide a button for
call rejecting.
Do the same as in the section To make an outgoing off-net call (VOIP PSTN call) step 6, implemented M800CallDelegate to listen for
the call
To reject the call, invoke M800IncomingCall.reject(Stringreason).
To answer the call, invoke M800IncomingCall.answer().
Note. The M800IncomingCall.callId() is different from the call ID from the incoming call notification bundle. If you want to match the call ID from
the incoming call notification bundle, follow the below steps:
Check if this is a push call by M800Call.isPuchCall().
If it is a push call, you can use M800Call.getPushCallId() to match with the incoming call notification bundle.
/**
* Event: call is ended for some reasons.
* @param call The call.
*/
void callTerminated(M800Call call, int status, Map<String,String>
userInfo);
The int status tells the call termination reason, that the caller has cancelled the call.
/**
* Sets the threshold while packet is lost.
* After that, the call would be teminated automatically.
*
* @param threshold The seconds for lossing packet.
*/
public abstract void setPacketLossThreshold(int threshold);
The communication packets keep transporting along the conversation. If there is no packet arrived to the device for the defined packet loss
threshold, the M800 call engine will determine this call as disconnected.
The communication packets keep transporting along the conversation. If there is no packet arrived to the device for the defined packet loss
threshold, the M800 call engine will determine this call as disconnected.
Reconnection configurations.
Set support reconnection
/**
*
* @param support {@value true} means the M800 call engine will attempt to restart a
call if it is disconnected.
*/
public abstract void setSupportCallReconnection(boolean support);
Set this value to be true so that the M800 call engine will attempt to restart a call if it is disconnected.
Set reconnection packet loss threshold
/**
* To set the delay to start call reconnection after network resume.
* <p>
* i.e. The total threshold in {@link
M800ClientConfiguration#getPacketLossThreshold()} should be longer than ((1 + {@link
M800ClientConfiguration#callReconnectionMaxRetries()})* ({@link
M800ClientConfiguration#callReconnectionPacketLossThresholdInMs()} + {@link
M800ClientConfiguration#callReconnectionTimeoutInSec()}))
* @param milliseconds The delay in milliseconds to start call reconnection after
network resume.
*
*/
public abstract void setCallReconnectionPacketLossThresholdInMs(int milliseconds);
To set the time delay starting call reconnection after network resumes.
Set reconnection maximum retries
/**
* To set the maximum number of reconnection retries.
* <p>
* i.e. The total maximum number of reconnection attempts = 1 + {@link
M800ClientConfiguration#callReconnectionMaxRetries()}
* @param retries
*/
public abstract void setCallReconnectionMaxRetries(int retries);
/**
* Set the hold tone to be played to the remote party if you hold the call.
* @param holdToneFilePath the file path of hold tone.
*/
public abstract void setHoldTone(String holdToneFilePath);
The hold tone is played to the remote party when you hold the call.
Set ring back tone
/**
* Set the ring back tone to be played locally when the user is dialing out a call.
* @param ringbackTonePath the file path of ring back tone.
*/
public abstract void setRingbackTone(String ringbackTonePath);
The ring back tone will be played locally when the user is dialing out a call. You have to enable this feature also by
/**
* Set the flag to enable playing ring back tone locally.
* @param support
*/
public abstract void setSupportPlayRingbackToneInEngine(boolean
support);
M800Audio am = M800SDK.getInstance().getRealtimeClient().getAudioManager();
if (am.isMute()){
am.unmute();
this.buttonMute.setText("Mute");
} else {
am.mute();
this.buttonMute.setText("Unmute");
}
@Override
public void callBeginTalking(M800Call call) {
//Your own implemetation
M800Audio am = M800SDK.getInstance().getRealtimeClient().getAudioManager();
if (am != null) {
am.playDisconnect();
}
}
Play a sound locally to notify user he/she has sent a DTMF (dual tone multi
frequency) tone over the call
Place the dtmf_1024.mp3 file in the res/raw directory of your project. You may copy this audio file from the demo project at the same
directory res/raw. Or, you may also provide your own audio file, but please be reminded that the file should be named as dtmf_1024.mp3.
The CallScreenActivity.java from demo project demonstrates how to send a DTMF tone over the call.
When the method of call M800Call.sendDTMF(String key) is invoked, with the presence of the dtmf_1024.mp3 file in the res/raw directory, the
DTMF tone would be played automatically.
When you receive the event, you should apply your own logic to dim the screen. For example, simply display a black screen on top of the
current Activity as to hide the buttons in UI. Below is the example how to handle the sensor event:
@Override
public final void onSensorChanged(SensorEvent event) {
float distance = event.values[0];
// Do something with this sensor data.
if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
// values[0]: Proximity sensor distance measured in centimeters
if (distance > 0) {
Log.d(DEBUG_TAG, "<onSensorChanged> Restoring screen brightness");
} else {
Log.d(DEBUG_TAG, "<onSensorChanged> Dimming screen");
}
}
}
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
If the call state equals to TelephonyManager.CALL_STATE_IDLE, it means that the phone is idle of call. The application can establish a
VOIP call at that moment.
Otherwise, if the phone is not idle of call while the application receives an incoming call notification bundle, the application should reject the
call by providing the bundle to the M800Client instance:
M800Client.rejectCallSinceBusyWithRemoteNotification(Bundle bundle). See the class GcmIntentService.java of demo project for full
implementation.
User attempts to make an outgoing VOIP call, the application should not create any M800Call object; instead, return user the response with
/**
* Hang-up or hold VOIP call when incoming GSM call immediately
*/
@Override
public void onCallStateChanged(int state, String incomingNumber) {
//Your implementation when the call state changes.
}
}
When a PSTN call interrupts the VOIP call, the application may decide to terminate the VOIP call or just hold the call. Consider also when
the PSTN call terminates, should the application resume the call screen and un-hold the call for user.
Vibration
System notification
Incoming call screen when device is locked
Etc.
<uses-permission android:name="android.permission.BLUETOOTH"/>
String regID =
GoogleCloudMessaging.getInstance(context).register(<GCM_APP_API_KEY>);
M800SDK.getInstance().getManagement().updatePushToken(regId,
IM800Management.PushType.GCM,
new M800ManagementCallback() {
@Override
public void complete(boolean isSuccess, M800Error error, Bundle userInfo) {
if (isSuccess) {
// Successfully uploaded
} else {
// Failed
}
}
});
JPush example:
After uploading the Registration ID to M800 server, your APP should be able to receive push via
GCMBroadcastReceiver or JPushBroadcastReceiver you implemented.
When receives any M800 push messages, you need to first start M800 connection. After that, you need to pass
the push message to M800 Realtime Client to see if it is an incoming call push or missed call push.
Please refer to com.m800.service.GCMIntentService for example.
IM Module
Introduction
The IM module in the m800SDK provides functionality to run single and multiple-user chat rooms in your app. There are two core features:
1-to-1 Chat. The single user chat (SUC) function allows a single user to send a message to another single user. The sent message can include
text, image, audio, location etc.
Group Chat. The multi-user chat (MUC) features allows a single user to send a message to a group of users. The sent message can include text,
image, audio, location, etc (same as 1-to-1 chat).
To enable IM features, you need a list of M800 contact. The contact list provides a set of JID with which you can to create a chat room. After the
chat room is created by one JID for SUC or multi JID for MUC, a message can be sent to the chat room. A chat room view controller should be
built and listening to the message changes from the SDK.
Note: this guide does not describe in detail how to build a chat room UI.
Pre-requisites
Successfully completed contact sync
How to Implement
Single User Chat Room(SUC)
As a start point...
Please get an instance of IM800SingleUserChatRoomManager from M800SDK.
IM800SingleUserChatRoomManager sucManager =
M800SDK.getInstance().getSingleUserChatRoomManager();
/**
* Create single user chat room.
* If the chat room is already existed, it will return this chat room.
*
* @param jid The jid of member
* @param callback The {@link CreateSingleUserChatRoomCallback}
whose {@link CreateSingleUserChatRoomCallback#complete(String, String)}
method will be called if the request is success, otherwise {@link
CreateSingleUserChatRoomCallback#error(String,
M800ChatRoomError, String)} method will be called.
*/
void createChatRoom(String jid, CreateSingleUserChatRoomCallback callback);
/**
* Callback for use with {@link IM800SingleUserChatRoomManager#createChatRoom(String,
CreateSingleUserChatRoomCallback)} to get the create/retrieve chat room result.
*
* If roomId is null, it will return {@link
M800ChatRoomError#INVALID_PARAMETER} from provided callback.
*
*/
interface CreateSingleUserChatRoomCallback {
/**
* Called on the main thread of the process to report that the chat room is
created/retrieved.
*
* @param roomId multi chat room ID
* @param jid The jid of member
*/
void complete(String roomId, String jid);
/**
* Called
chat room.
*
* @param
* @param
* @param
*/
on the main thread of the process to report that fail to create single
Take the demo project as an example; please refer to the class ChatRoomApiDemoCreateSUCActivity.java.
sucManager.createChatRoom(
selectedJid,
new IM800SingleUserChatRoomManager.CreateSingleUserChatRoomCallback() {
@Override
public void complete(String roomId, String jid) {
//If success, a related roomId will be return here.
}
@Override
public void error(String jid, M800ChatRoomError error, String message) {
//If failure, please read the error message to find the reason.
}
}
);
To create SUC, it just creates a related data in local database; it doesnt need to send request to server. That mean, SDK will not validate
the provided JID (Definition of Jabber Identifier). As long as, the provided JID is not empty, it must be return success result. If it returns
failure result, please check if the provided JID is not empty. (Please note that, if the JID is not existed, related chat room impossible to
receive any message from server.)
If the SUC is already created for given JID, it will return the existing chat room ID.
/**
* Register a listener that listeners events of all single user chat rooms.
*
* @param listener a listener implements {@link IM800SingleUserChatRoomListener}
* @throws NullPointerException if listener is null
*/
void addChatRoomListener(IM800SingleUserChatRoomListener listener);
/**
* Register a listener that listeners events of a single user chat room.
*
* @param roomID single user chat room ID
* @param listener a listener implements {@link IM800SingleUserChatRoomListener}
* @throws NullPointerException if listener is null
* @throws IllegalStateException if roomID is null or empty
*/
void addChatRoomListener(String roomID, IM800SingleUserChatRoomListener listener);
/**
* Callback for use with {@link
IM800SingleUserChatRoomManager#addChatRoomListener(IM800SingleUserChatRoomListener)}
to monitor the activity of all single chat room.
* Callback for use with {@link
IM800SingleUserChatRoomManager#addChatRoomListener(String,
IM800SingleUserChatRoomListener)} to monitor the activity of specified single
chat room.
*/
public interface IM800SingleUserChatRoomListener {
/**
* Called on the main thread of the process to report that a new single chat room
has been created.
*
* @param roomId single user chat room ID
*/
void onChatRoomCreated(String roomId);
/**
* Called on the main thread of the process to report that an existing single chat
room has been removed from local database.
*
* @param roomId single user chat room ID
*/
void onChatRoomRemoved(String roomId);
/**
* Called on the main thread of the process to report that chat activity occurs.
*
* @param roomId single user chat room ID
* @param lastUpdateTime last chat time
*/
void onLastUpdateTimeChanged(String roomId, Date lastUpdateTime);
}
Take the demo project as an example. Please refer to the class ChatRoomListFragment.java.
We recommend that you keep the reference object of the listener, since developer needs it to stop related monitoring.
To stop monitoring SUC Activity, please invoke removeChatRoomListener() to stop monitor SUC activity.
/**
* Unregister a single user chat room listener.
*
* @param listener a listener previously registered
* @throws NullPointerException if listener is null
*/
void removeChatRoomListener(IM800SingleUserChatRoomListener listener);
We recommend that, if developers no longer need to monitor SUC Activity, please do not forget to invoke removeChatRoomListener() t
o stop monitoring:
sucManager.removeChatRoomListener(mySUCListener);
/**
* Unregister all single user chat room listeners.
*/
void clearChatRoomListeners();
Like so:
sucManager.clearChatRoomListeners();
/**
* Get all single user chat rooms.
*
* @return list of single user chat rooms
*/
@NonNull
List<IM800SingleUserChatRoom> getChatRooms();
Take the demo project as an example. Please refer to the class ChatRoomListFragment.java.
The above method will query from local database with the sequence descending order of last chat time, and return full list of SUC model
objects.
To retrieve specified SUC model objects, SDK has provided two ways for this query. One is to retrieve SUC model object by JID:
/**
* Obtain specific single user chat room.
*
* @param jid The jid of member
* @return single user chat room if found, null otherwise.
*/
IM800SingleUserChatRoom getChatRoomByJID(String jid);
/**
* Obtain specific single user chat room.
*
* @param roomId single chat room ID
* @return single user chat room if found, null otherwise.
*/
IM800SingleUserChatRoom getChatRoomById(String roomId);
Since the above retrieval methods are related to database query action, we recommend that, developer should invoke these methods in
a background thread, thus avoid blocking the main thread.
To remove the SUC related data from local database, please invoke deleteChatRoom() to start SUC Deletion.
/**
* Delete the chat room and all related data in local database.
*
* @param roomId single chat room ID
* @return true if this chat room was deleted, false otherwise.
*/
boolean deleteChatRoom(String roomId);
This method will return true if the related SUC was found and deleted, return false otherwise.
Take the demo project as an example; please refer to the class ChatRoomListFragment.java.
sucManager.deleteChatRoom(roomId);
Since the above deletion method related to database delete action, we recommend that, developer should invoke this methods in
background thread, thus avoid block the main thread process.
/**
* Get participants in a single user chat room.
*
* @param roomId single chat room ID
* @return participant list including current user and the other participant
*/
@NonNull
List<IM800SingleUserChatRoomParticipant> getParticipants(String roomId);
The above method will query from local database, and return full list of SUC Participant model objects.
Since the above retrieval methods are related to database query action, we recommend that, developer should invoke this method on a
background thread, thus avoid blocking the main thread process.
IM800MultiUserChatRoomManager mucManager =
M800SDK.getInstance().getMultiUserChatRoomManager();
/**
* Create multi user chat room
* Title cannot be empty
* Please at least invite two members
*
* @param title The title of chat room
* @param jids JID the unique identifier of an M800 user, the members will be
invite.
* @param callback an asynchronous callback of create chat room result,
*
{@link CreateMultiUserChatRoomCallback#complete(String, String,
String[])} method will be called if the request is success,
*
otherwise {@link CreateMultiUserChatRoomCallback#error(String,
String[], M800ChatRoomError, String)} method will be called.
*/
void createChatRoom(String title, String[] jids, CreateMultiUserChatRoomCallback
callback);
interface CreateMultiUserChatRoomCallback {
/**
* Called when create-chat-room request is accepted by server.
*
* <p>Please note when this callback is invoked, the group chat room is not
created in client SDK yet.
* To monitor chat room creation event, register a listener to listen {@link
IM800MultiUserChatRoomListener#onChatRoomCreated(String)}.</p>
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param title The title of chat room
* @param jids JID the unique identifier of an M800 user, the members will be
invite.
*/
void complete(String roomId, String title, String[] jids);
/**
* Called when create chat room is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param title The title of chat room
* @param jids JID the unique identifier of an M800 user, the members will be
invite.
* @param error simplified error result
* @param message detail error result
*/
void error(String title, String[] jids, M800ChatRoomError error, String message)
}
Compare with SUC creation, MUC creation has different workflow. Even if the request is success, it will not create the related data in local
database immediately. Until receive a MUC invitation message from server, it would insert this related data into local database. To monitor when
the related MUC created, please see addChatRoomListener().
Use the following API to get maximum number of group chat room members allowed in one room.
mucManager.getMaxParticipantNum()
/**
* Register a listener that listeners events of all multi user chat rooms.
*
* @param listener a listener implements {@link IM800MultiUserChatRoomListener}
* @throws NullPointerException if listener is null
*/
void addChatRoomListener(IM800MultiUserChatRoomListener listener);
/**
* Register a listener that listeners events of a multi user chat room.
*
* @param roomId multi user chat room ID
* @param listener a listener implements {@link IM800MultiUserChatRoomListener}
* @throws NullPointerException if listener is null
* @throws IllegalStateException if roomID is null or empty
*/
void addChatRoomListener(String roomId, IM800MultiUserChatRoomListener listener);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#addChatRoomListener(IM800MultiUserChatRoomListener)} to
monitor the activity of all multi chat room.
* Callback for use with {@link
IM800MultiUserChatRoomManager#addChatRoomListener(String,
IM800MultiUserChatRoomListener)} to monitor the activity of specified multi chat room.
*/
public interface IM800MultiUserChatRoomListener
{
/**
* Called on the main thread of the process to report that a new multi chat room
has been created.
*
* @param roomId multi user chat room ID
*/
void onChatRoomCreated(String roomId);
/**
* Called on the main thread of the process to report that an existing multi chat
We recommend that you keep the reference object of the listener, since developer needs it to stop related monitoring.
To stop monitoring MUC Activity, please invoke removeChatRoomListener() to stop monitor MUC activity.
/**
* Unregister a multi user chat room listener.
*
* @param listener a listener previously registered
* @throws NullPointerException if listener is null
*/
void removeChatRoomListener(IM800MultiUserChatRoomListener listener);
We recommend that, if developers don't need to monitoring MUC Activity any more, please don't forget invoke removeChatRoomListener() to
stop monitoring.
To stop all SUC Activity monitoring, please invoke clearChatRoomListeners() to stop monitor all SUC activity.
/**
* Unregister all multi user chat room listeners.
*/
void clearChatRoomListeners();
/**
* Get all multi user chat rooms.
*
* @return list of multi user chat room.
*/
List<IM800MultiUserChatRoom> getChatRooms();
/**
* Obtain specific multi user chat room.
*
* @param roomId multi chat room ID
* @return multi user chat room if found, null otherwise.
*/
IM800MultiUserChatRoom getChatRoomById(String roomId);
Since the above retrieval methods are related to database query action, we recommend that, developer should invoke these methods in a
/**
* Get active participants whose role are {@link
com.m800.sdk.chat.muc.IM800MultiUserChatRoomParticipant.Role#Member} in a multi user
chat room.
*
* @param roomId multi user chat room ID
* @return list of all active participants whose role are {@link
com.m800.sdk.chat.muc.IM800MultiUserChatRoomParticipant.Role#Member}
*/
List<IM800MultiUserChatRoomParticipant> getMembers(String roomId);
To retrieve full list of active administrators in specified MUC, please invoke getAdministrators().
/**
* Get active participants whose role are {@link
com.m800.sdk.chat.muc.IM800MultiUserChatRoomParticipant.Role#Admin} in a multi user
chat room.
*
* @param roomId multi user chat room ID
* @return list of all active participants whose role are {@link
com.m800.sdk.chat.muc.IM800MultiUserChatRoomParticipant.Role#Admin}
*/
List<IM800MultiUserChatRoomParticipant> getAdministrators(String roomId);
/**
* Find a participant, which is already joined a multi user chat room or joined some
time in the past.
*
* @param jid JID the unique identifier of an M800 user
* @param roomId multi user chat room ID
* @return participant if found, null otherwise.
*/
IM800MultiUserChatRoomParticipant findParticipant(String jid, String roomId);
/**
* Request to start group chat room data synchronization task.
* <p>
*
If synchronization task is executed once, and force is not set to true, no
synchronization task will be executed.
*
Only one synchronization task will be executed at one time, no duplicate
request allowed.
* </p>
*
* @param force force update
*/
void syncData(boolean force);
To determine when developers need to invoke sync() to trigger MUC synchronisation task, invoke isDataSynced():
/**
* Indicates whether multi user chat room data synchronization task is finished or
not.
*
* @return whether the multi user chat room data synchronization task is finished or
not
*/
boolean isDataSynced();
/**
* Indicates whether multi user chat room data synchronization task is running or not.
*
* @return whether multi user chat room data synchronization task is running or not.
*/
boolean isDataSyncing();
If you want to trigger MUC synchronization task for specific MUC, invoke syncData():
/**
* Request to start single MUC synchronization task.
*
* @param roomId
multi chat room ID
* @param callback an asynchronous callback of MUC synchronization result, {@link
SyncMultiUserChatRoomCallback#complete(String)} method will be called if the request
is success, otherwise {@link SyncMultiUserChatRoomCallback#error(String,
M800ChatRoomError, String)} method will be called.
*/
void syncData(String roomId, SyncMultiUserChatRoomCallback callback);
/**
* Callback for use with {@link IM800MultiUserChatRoomManager#syncData(String,
SyncMultiUserChatRoomCallback)} to get the request result.
*/
interface SyncMultiUserChatRoomCallback {
/**
* Called when MUC synchronization is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
*/
void complete(String roomId);
/**
* Called when MUC synchronization is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, M800ChatRoomError error, String message);
}
/**
* Invite members to join a specific chat
room.
*
* @param roomId
multi chat room ID
* @param jids
JID the unique identifier of an M800 user, the members will be
invite.
* @param callback an asynchronous callback of invite member result, {@link
InviteMembersCallback#complete(String, String[])} method will be called if
the request is success, otherwise {@link InviteMembersCallback#error(String,
String[], M800ChatRoomError, String)} method will be called.
*/
void inviteMembers(String roomId, String[] jids,
InviteMembersCallback callback);
/**
* Callback for use with {@link IM800MultiUserChatRoomManager#inviteMembers(String,
String[], InviteMembersCallback)} to get the request result.
*/
interface InviteMembersCallback {
/**
* Called when invite member is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jids JID the unique identifier of an M800 user
*/
void complete(String roomId, String[] jids);
/**
* Called when invite member is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jids JID the unique identifier of an M800 user
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, String[] jids, M800ChatRoomError error, String message);
}
As an administrator, you can force specific user to leave the chat room by invoking kickMember():
/**
* Force members leave the specific chat room.
*
* @param roomId
multi chat room ID
* @param jid
JID the unique identifier of an M800 user, the member will be kick.
* @param callback an asynchronous callback of leave member result, {@link
KickMemberCallback#complete(String, String)} method will be called if the request is
success, otherwise {@link KickMemberCallback#error(String, String, M800ChatRoomError,
String)} method will be called.
*/
void kickMember(String roomId, String jid, KickMemberCallback callback);
Upon successful request, kicked users will no longer be able to chat in the room. However, they are still able to read old messages stored in the
chat room.
/**
* Callback for use with {@link IM800MultiUserChatRoomManager#kickMember(String,
String, KickMemberCallback)} to get the request result.
*/
interface KickMemberCallback {
/**
* Called when kick member is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jid JID the unique identifier of an M800 user
*/
void complete(String roomId, String jid);
/**
* Called when kick member is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jid JID the unique identifier of an M800 user
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, String jid, M800ChatRoomError error, String message);
}
As an administrator of a chatroom, you can promote or demote other users by calling the API below.
/**
* Promote member to become administrator.
*
* @param roomId
multi chat room ID
* @param jid
JID the unique identifier of an M800 user, the member will be
promote become admin.
* @param callback an asynchronous callback of promote member result, {@link
PromoteMemberCallback#complete(String, String)} method will be called if the request
is success, otherwise {@link PromoteMemberCallback#error(String, String,
M800ChatRoomError, String)} method will be called.
*/
void promoteMember(String roomId, String jid, PromoteMemberCallback callback);
/**
* Callback for use with {@link IM800MultiUserChatRoomManager#promoteMember(String,
String, PromoteMemberCallback)} to get the request result.
*/
interface PromoteMemberCallback {
/**
* Called when promote member is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jid JID the unique identifier of an M800 user
*/
void complete(String roomId, String jid);
/**
* Called when promote member is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jid JID the unique identifier of an M800 user
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, String jid, M800ChatRoomError error, String message);
}
/**
* Demote administrator to become member.
*
* @param roomId
multi chat room ID
* @param jid
The jid of administrator, the administrator will be demote become
member.
* @param callback an asynchronous callback of demote member result, {@link
DemoteAdministratorCallback#complete(String, String)} method will be called if the
request is success, otherwise {@link DemoteAdministratorCallback#error(String, String,
M800ChatRoomError, String)} method will be called.
*/
void demoteAdministrator(String roomId, String jid, DemoteAdministratorCallback
callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#demoteAdministrator(String, String,
DemoteAdministratorCallback)} to get the request result.
*/
interface DemoteAdministratorCallback {
/**
* Called when demote administrator without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jid JID the unique identifier of an M800 user
*/
void complete(String roomId, String jid);
/**
* Called when demote administrator with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param jid JID the unique identifier of an M800 user
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, String jid, M800ChatRoomError error, String message);
}
/**
* Allow current user leave specific chat room.
*
* @param roomId
multi chat room ID
* @param callback an asynchronous callback of leave chat room result, {@link
LeaveRoomCallback#complete(String)} method will be called if the request is success,
otherwise {@link LeaveRoomCallback#error(String, M800ChatRoomError, String)} method
will be called.
*/
void leaveRoom(String roomId, LeaveRoomCallback callback);
Upon successful request, the user will no longer be able to chat in the room. However, they are still able to read old messages stored in the chat
room.
/**
* Callback for use with {@link IM800MultiUserChatRoomManager#leaveRoom(String,
LeaveRoomCallback)} to get the request result.
*/
interface LeaveRoomCallback {
/**
* Called when leave room is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
*/
void complete(String roomId);
/**
* Called when leave room is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, M800ChatRoomError error, String message)
}
Even if you leave the room, you still can retrieve this room from the local database.
/**
* Delete the chat room and all related data in local database.
*
* @param roomId multi chat room ID
* @return true if this chat room was deleted, false otherwise.
*/
boolean deleteChatRoom(String roomId);
/**
* Enable the mute mode of the chat room.
* This just a boolean to let client side setup corresponding notification for chat
room.
*
* @param roomId multi chat room ID
* @param isMute True if want to enable mute mode, false otherwise
* @param callback an asynchronous callback of enable mute mode result, {@link
SetMuteModeCallback#complete(String, boolean)} method will be called if the request is
success, otherwise {@link SetMuteModeCallback#error(String, M800ChatRoomError,
String)} method will be called.
*/
void setMuteModeEnabled(String roomId, boolean isMute, SetMuteModeCallback callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#setMuteModeEnabled(String, boolean,
SetMuteModeCallback)} to get the request result.
*/
interface SetMuteModeCallback {
/**
* Called when enable/disable mute mode without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param isMuted True if mute mode is enabled, false otherwise
*/
void complete(String roomId, boolean isMuted);
/**
* Called when enable/disable mute mode with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, M800ChatRoomError error, String message);
}
/**
* Enable the smart notification of the chat room.
* This just a boolean to let client side setup corresponding notification for chat
room.
*
* @param roomId multi chat room ID
* @param enable True if smart notification is enabled, false otherwise
* @param callback an asynchronous callback of enable smart notification result,
{@link SetSmartNotificationCallback#complete(String, boolean)} method will be called
if the request is success, otherwise {@link SetSmartNotificationCallback#error(String,
M800ChatRoomError, String)} method will be called.
*/
void setSmartNotificationEnabled(String roomId, boolean enable,
SetSmartNotificationCallback callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#setSmartNotificationEnabled(String, boolean,
SetSmartNotificationCallback)} to get the request result.
*/
interface SetSmartNotificationCallback {
/**
* Called when enable/disable smart notification without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param isEnabled True if smart notification is enabled, false otherwise
*/
void complete(String roomId, boolean isEnabled);
/**
* Called when enable/disable smart notification with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, M800ChatRoomError error, String message);
}
As an administrator, you can manage the chat room properties by using the API below.
To change the name of chat room, invoke changeChatRoomName():
/**
* Send a message to server, request update the name of multi chat room.
*
* @param roomId
multi chat room ID
* @param title
The title of chat room
* @param callback an asynchronous callback of update chat room name result, {@link
ChangeChatRoomNameCallback#complete(String, String)} method will be called if the
request is sent, otherwise {@link ChangeChatRoomNameCallback#error(String, String,
M800ChatRoomError, String)} method will be called.
*/
void changeChatRoomName(String roomId, String title, ChangeChatRoomNameCallback
callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#changeChatRoomName(String, String,
ChangeChatRoomNameCallback)} to get the request result.
*/
interface ChangeChatRoomNameCallback {
/**
* Called when update chat room name request is sent without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param title The title of chat room
*/
void complete(String roomId, String title);
/**
* Called when update chat room name request is sent with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param title The title of chat room
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, String title, M800ChatRoomError error, String message);
}
/**
* Send a message to server, request update the icon of multi chat room.
*
* @param roomId
multi chat room ID
* @param iconBitmap
Image bitmap, size should be smaller than 50KB, will be
recycled after process completed, either success or failure
* @param callback
an asynchronous callback of update chat room icon result,
{@link ChangeChatRoomIconCallback#complete(String)} method will be called if the
request is sent, otherwise {@link ChangeChatRoomIconCallback#error(String,
M800ChatRoomError, String)} method will be called.
*/
void changeChatRoomIcon(String roomId, Bitmap iconBitmap, ChangeChatRoomIconCallback
callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#changeChatRoomIcon(String, Bitmap,
ChangeChatRoomIconCallback)} to get the request result.
*/
interface ChangeChatRoomIconCallback {
/**
* Called when update chat room icon request is sent without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
*/
void complete(String roomId);
/**
* Called when update chat room icon request is sent with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, M800ChatRoomError error, String message);
}
/**
* Send a message to server, request update the theme id of multi chat room.
*
* @param roomId
multi chat room ID
* @param themeId
The theme Id of chat room, which is defined by client side. Just a
string value to let client side setup corresponding theme for chat room.
* @param callback an asynchronous callback of update chat room theme id result,
{@link ChangeChatRoomThemeIdCallback#complete(String, String)} method will be called
if the request is sent, otherwise {@link ChangeChatRoomThemeIdCallback#error(String,
String, M800ChatRoomError, String)} method will be called.
*/
void changeChatRoomThemeId(String roomId, String themeId,
ChangeChatRoomThemeIdCallback callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#changeChatRoomThemeId(String,
String, ChangeChatRoomThemeIdCallback)} to get the request result.
*/
interface ChangeChatRoomThemeIdCallback {
/**
* Called when update the theme id
request is sent without error.
*
* <p>This
callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param themeId
The theme Id of chat room, which is defined by client side.
Just a
string value to let client side setup corresponding theme for chat room.
*/
void complete(String roomId, String themeId);
/**
* Called when update the theme id request
is sent with error.
*
* <p>This
callback is called on application's main thread.</p>
*
* @param roomId multi chat room ID
* @param themeId
The theme Id of chat room, which is defined by client side.
Just a
string value to let client side setup corresponding theme for chat room.
* @param error simplified error result
* @param message detail error result
*/
void error(String roomId, String themeId, M800ChatRoomError error, String
message);
When SDK received server message about MUC icon changed, SDK will build cache for this icon. But, if user clear the app cache, this cache may
also lost. To recover the cache, please invoke buildChatRoomIconCacheFile().
/**
* Trigger a process to rebuild the cache file.
*
* @param roomIds list of multi user chat room ID
* @param callback callback an asynchronous callback of rebuild the cache file result,
{@link BuildChatRoomIconCacheFileCallback#onResult(String[], String[])} method will be
called if the build cache process is finished.
*/
void buildChatRoomIconCacheFile(String[] roomIds, BuildChatRoomIconCacheFileCallback
callback);
/**
* Callback for use with {@link
IM800MultiUserChatRoomManager#buildChatRoomIconCacheFile(String[],
BuildChatRoomIconCacheFileCallback)} to get the process result.
*/
interface BuildChatRoomIconCacheFileCallback {
/**
* Called when build cache process is
finished.
*
* <p>This
callback is called on application's main thread.</p>
*
* @param success list of multi user chat room ID, which is rebuild icon
cache file successfully
* @param failure list of multi user chat room ID, which is rebuild icon
cache file failure, that should be decode image data failure.
*/
void onResult(String[] success, String[] failure)
}
To distinguish if the chat room is missing icon cache or icon not defined, please consider the following code:
List<IM800MultiUserChatRoom> mucItems =
M800SDK.getInstance().getMultiUserChatRoomManager().getChatRooms();
for (IM800MultiUserChatRoom chatRoom : mucItems) {
if (chatRoom.hasRoomIcon() && chatRoom.getRoomIconThumbnail() == null) {
//icon cache is lost, please rebuild.
}
}
IM800SystemChatRoomManager mSystemChatManager =
M800SDK.getInstance().getSystemChatRoomManager();
/**
* Register a listener that listeners events of system chat room.
*
* @param listener a listener implements {@link IM800SystemChatRoomListener}
* @throws NullPointerException if listener is null
*/
void addChatRoomListener(IM800SystemChatRoomListener listener);
/**
* Callback for use with {@link
IM800SystemChatRoomManager#addChatRoomListener(IM800SystemChatRoomListener)} to
monitor the activity of system chat room.
*/
public interface IM800SystemChatRoomListener {
/**
* Called on the main thread of the process to report that system chat room has
been created.
*
* @param roomId single user chat room ID
*/
void onChatRoomCreated(String roomId);
/**
* Called on the main thread of the process to report that chat activity occurs.
*
* @param roomId system chat room ID
* @param lastUpdateTime last chat time
*/
void onLastUpdateTimeChanged(String roomId, Date lastUpdateTime);
}
We recommend that you keep the reference object of the listener, since developer needs it to stop related monitoring.
To stop monitoring System Chat Room Activity, please invoke removeChatRoomListener() to stop monitor System Chat Room activity.
/**
* Unregister a system chat room listener.
*
* @param listener a listener previously registered
* @throws NullPointerException if listener is null
*/
void removeChatRoomListener(IM800SystemChatRoomListener listener);
To stop all System Chat Room Activity monitoring, please invoke clearChatRoomListeners() to stop monitor all System Chat Room activity.
/**
* Unregister all system chat room listeners.
*/
void clearChatRoomListeners();
/**
* Retrieve system chat room object.
*
* @return system chat room object
*/
IM800ChatRoom getSystemChatRoom();
M800SDK.getInstance().getSMSChatRoomManager();
M800SDK.getInstance().getSMSChatRoomManager().createChatRoom("phoneNumber",
new IM800SMSChatRoomManager.CreateSMSChatRoomCallback() {
@Override
public void complete(String roomId, String phoneNumber) {
// Chat room created
}
@Override
public void error(String phoneNumber, M800ChatRoomError error, String
message) {
// Chat room creation failed
}
});
You can register the chat room events listener to a one SMS chat room or all:
mSMSChatRoomManager.getChatRooms();
mSMSChatRoomManager.getChatRoomById(roomID);
mSMSManager.deleteChatRoom(roomID);
Messaging
Introduction
User can send and receive various types of M800 chat messages in chat rooms.
M800 chat message contains the following key attributes:
Message ID: A unique identifier of a M800 chat message
Room ID: An M800 chat rooms ID where the chat message belongs to.
Direction: Either incoming or outgoing.
Status: For incoming messages, the status could be read or unread. For outgoing messages, the status could be processing, delivering,
delivered, delivery failed, server received, client received.
Content Type: Can be text, audio, image, ephemeral image, video or system notifications like member join, member promote, etc.
Location: User can choose to share his/her location in a message by simply providing latitude and longitude.
M800SDK.getInstance().getChatMessageManager();
Description
-1
7001
7002
HTTP exception.
7003
7401
7900
7901
others
The following code demos how to add and remove a chat message listener:
M800SDK.getInstance().getChatMessageManager().addChatMessageListener(mRoomId,
mMessageListener);
M800SDK.getInstance().getChatMessageManager().removeChatMessageListener(mMessageListen
er);
If onChatMessageDataChanged(messageID, bundle) callback is called, that means an existing M800 messages data has been updated. If you
have an instance of IM800ChatMessage that has the same messageID which you get from onNewIncomingChatMessage(message) or onNewOu
M800SDK.getInstance().getChatMessageManager().setMediaFileTransferListener("messageID"
, <Implementation of IM800FileTransferListener>);
/**
* Get chat message with ID.
*
* @param messageID chat message ID
* @return chat message, null if not found
* @throws IllegalArgumentException
*/
IM800ChatMessage getChatMessage(String messageID);
/**
* Get last chat messages in a chat room.
*
* @param roomID chat room ID
* @return last chat message, if no room is found with the roomID, null will be
returned
* @throws IllegalArgumentException
*/
IM800ChatMessage getLastChatMessage(String roomID);
/**
* Get chat messages in a chat room.
*
* @param roomID chat room ID
* @param limit maximum count of chat messages that will return
* @param dateOrderDesc if set to true, chat messages will be ordered by date DESC,
otherwise date ASC
* @return list of chat messages
* @throws IllegalArgumentException
*/
List<IM800ChatMessage> getChatMessages(String roomID, int limit, boolean
dateOrderDesc);
/**
* Get chat messages in a chat room.
*
* @param roomID chat room ID
* @param limit maximum count of chat messages that will return
* @param fromDate if dateOrderDesc is set to true, will only return chat messages
earlier(include) than this date;
*
if dateOrderDesc is set to false, will only return chat messages
later(include) than this date
* @param dateOrderDesc if set to true, chat messages will be ordered by date DESC,
otherwise date ASC
* @return list of chat messages
* @throws IllegalArgumentException
*/
List<IM800ChatMessage>
getChatMessages(String roomID, int limit, Date fromDate, boolean dateOrderDesc);
/**
* Get chat messages in a chat room.
*
* @param roomID chat room ID
* @param limit maximum count of chat messages that will return
* @param messageID if dateOrderDesc is set to true, will only return chat messages
earlier than this message;
*
if dateOrderDesc is set to false, will only return chat messages
later than this message
* @param dateOrderDesc if set to true, chat messages will be ordered by date DESC,
otherwise date ASC
* @return list of chat messages
* @throws IllegalArgumentException
*/
List<IM800ChatMessage> getChatMessages(String roomID, int limit, String messageID,
boolean dateOrderDesc);
There are APIs in IM800ChatMessageManager that are able to get the number of chat messages in a chat room and unread chat rooms count.
/**
* Get chat messages count in a chat room.
*
* @param roomID chat room ID
* @return chat messages count, if no room is found with the roomID, 0 will be
returned
* @throws IllegalArgumentException
*/
int getChatMessagesCount(String roomID);
/**
* Get unread chat messages count in a chat room.
*
* @param roomID chat room ID
* @return unread chat messages count, if no room is found with the roomID, 0 will be
returned
* @throws IllegalArgumentException
*/
int getUnreadChatMessagesCount(String roomID);
/**
* Get unread chat messages count of all chat rooms.
*
* @return unread chat messages count of all chat rooms
*/
int getUnreadChatMessagesCount();
/**
* Get number of chat rooms that has unread messages.
*
* @return number of chat rooms that has unread messages
*/
int getUnreadChatRoomsCount();
In multi-user chat room, except from normal messages like text or media messages, user will also receive some system notification messages.
The following code demonstrate how to read a system notification message:
/**
* Get image bitmap array in an ephemeral chat message.
*
* @param messageID ephemeral chat message ID
* @return ephemeral message's image in byte array,
* null if the message is not found, or not ephemeral message, or ephemeral image is
already timeout
* @throws IllegalArgumentException if messageID is null or empty
*/
byte[] getEphemeralImageBitmapArray(String messageID);
After showing an ephemeral messages image to user, you should start a timer to count the display time. If the messages time to live (TTL) valu
e is reached, you should clear ephemeral messages data and set its time to live value to zero so that the user cannot see this message anymore.
To do so, call the following APIs in IM800ChatMessageManager.
/**
* Set an ephemeral chat message's time to live value.
*
* <p>When an ephemeral message's TTL is set to 0,
* you should also call {@link #removeEphemeralMessageImage(String)} to clear its
image data.</p>
*
* @param messageID ephemeral chat message ID
* @param TTL time to live, should be greater than or equal to 0
* @return true if set TTL successfully, otherwise false
* @throws IllegalArgumentException if messageID is null or empty
*/
boolean setEphemeralMessageTTL(String messageID, @Nonnegative int TTL);
/**
* Remove image data stored in an ephemeral chat message.
*
* <p>Next time when {@link #getEphemeralImageBitmapArray(String)} is called, it will
return null.</p>
*
* @param messageID ephemeral chat message ID
* @return true if remove ephemeral image successfully, otherwise false
* @throws IllegalArgumentException if messageID is null or empty
*/
boolean removeEphemeralMessageImage(String messageID);
private
class RemoveMessageTask extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
String messageID = params[0];
return M800SDK.getInstance().getChatMessageManager().removeMessage(messageID)
> 0;
}
@Override
protected void onPostExecute(Boolean isSuccess) {
if (isSuccess) {
// Update UI
}
}
}
The following code demos how to remove all (non-system) chat messages in a chat room.
private
class RemoveMessageTask extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
String roomID = params[0];
M800SDK.getInstance().getChatMessageManager().removeAllMessagesInRoom(roomID);
// OR
M800SDK.getInstance().getChatMessageManager().removeAllNonSystemChatMessages(roomID);
return null;
}
}
private
class MarkChatMessageAsReadTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// Mark chat messages as read
M800SDK.getInstance().getChatMessageManager().markAllChatMessagesAsRead(mRoomId);
// Then can send displayed receipt so others
// know user have read the messages
M800SDK.getInstance().getChatMessageManager().sendDisplayedReceipt(mRoomId);
return null;
}
}
If user doesnt connect to M800 server when he reads the chat messages, you should still mark the messages as read and call the following API
in IM800ChatMessageManager to resend all display receipts when connected.
/**
* Resend all displayed receipts that failed to send before.
*
* <p>If chat messages are marked as read correctly
* and {@link #sendDisplayedReceipt(String)} is never been called,
* will send displayed receipts for all chat rooms if needed.</p>
*/
void resendDisplayedReceipts();
/**
* Send chat state in a chat room.
*
* <p>Chat state message tells other chat participants whether user is typing or not.
* Don't send {@link ChatState#Composing} state too frequently if user keeps typing,
* recommended interval is 2 seconds.</p>
*
* @param roomID chat room ID, if no room is found with this ID, nothing will be sent
* @param state the {@link ChatState} chat state
* @return error with code {@link M800ChatRoomError#NO_ERROR} if message is sent,
* otherwise see {@link M800ChatRoomError}
* @throws IllegalArgumentException
*/
M800ChatRoomError sendChatState(String roomID, ChatState state);
/**
* Implement this listener to listen all {@link ChatState} events in a chat room.
*/
interface ChatStateListener {
/**
* The event will be triggered when the chat state of a chat room changed
*
* @param roomId the roomId of the chat room.
* @param jid
the JID of chat participant who triggers the event.
* @param state the state of the chat participant.
*/
void onChatStateChanged(String roomId, String jid, ChatState state);
}
And then, add the listener to the IM800ChatMessageManager instance by invoking the below method.
/**
* Add a chat state listener that listens to chat state event of the chat room with
provided roomID.
*
* @param roomID chat room id
* @param listener chat state listener
* @throws IllegalArgumentException if roomID or listener is null
*/
void addChatStateListener(String roomID, ChatStateListener listener);
Credit Module
Introduction to Credit Module
The credit module provides simple APIs to get the credit information of the current user. The application may also listen for the instant credit
update events through the credit module.
Pre-requisites
User must have signed up on the application before getting the credit information. User credit information can be provided only if the project
provision supports user wallet feature. Please confirm this with M800 project managers.
How to Implement
In this section, we introduce the details on how to implement and use the credit module.
Get the IM800CreditManager instance. You may invoke M800SDK.getInstance().getCreditManager().
The class MainActivity.java of demo app demonstrates the usage of the APIs. You may also see the Java Documentation of IM800CreditM
anager for full description.
Note. IM800CreditManager provides the credit information only when user has signed up to the M800 server.
To listen for the credit update events from IM800CreditManager, please implement IM800CreditListener. Pass the implemented IM800Cr
editListener object to IM800CreditManager by invoking IM800CreditManager.addCreditListener(listener).
ApplicationClass.java of the demo app demonstrates how to add the IM800CreditListener listener:
Contact Management
Introduction
After user finds some M800 users by phone number, location or recommendation, he/she can add them as his/her M800 contact. Later if the user
swaps device or reinstalls the app, he/she can retrieve M800 contacts added this way automatically after contact sync.
How to implement
Add Contact
User can add an M800 user into his/her contact list providing the JID.
You should check validity of the JID before calling this API (See Find User section).
M800SDK.getInstance().getContactManager().addM800Contact(JID, addOrRemoveCallback);
Remove contact
User can remove contacts added, only by using the API above. The M800 contacts found in users native address book cannot be removed using
this API because they are linked to native contacts.
However, user can go to native address book app and remove the native contact there. After contact sync in M800SDK, the associated M800
contact will be removed automatically.
M800SDK.getInstance().getContactManager().removeM800Contact(JID, addOrRemoveCallback);
interface AddOrRemoveContactCallback {
void onComplete(String JID);
void onError(String JID, M800Error error);
}
Pre-requisites
The user has signed in.
How to implement
To retrieve an instance of the RateManager:
Retrieve an instance of the IM800RateManager, like so:
mM800RateManager.addRateTableListener(m800RateTableListener);
mM800RateManager.update(context);
Note:
1. The updated result notifies the application ONLY if you have listen for the rate table event by IM800RateTableListener.
2. No operation would be started if there is no update in the RateManager.
To retrieves rates:
Call getRateInfoItems on the RateManager and specify the type.
For SMS, pass in IM800RateManager.ChargingRateType.SMS as parameter:
To retrieve the rates with keyword filter. (Search by country name or country code)
Note: You should never invoke the above API on the UI thread. This method requires database reading which may block the UI thread tasks. The
class RateInfoListFragment.java of demo app demonstrates how to get rate list.
How to Implement
As a starting point, from M800SDK, get an instance of IM800FindUserManager.
If the method above returns null, user hasnt signed up. Sign up is necessary before using M800SDK.
/**
* Callback for use with {@link
IM800FindUserManager#findM800UserByPhoneNumberFromServer(String,
FindM800UserByPhoneNumberCallback)} to get the request result.
*/
interface FindM800UserByPhoneNumberCallback {
/**
* Called when M800 user search is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param phoneNumber phoneNumber the phone number used during search
* @param userProfile the search result, if result not found, that should be null
* @param isContact indicates whether the related user is friend or not
*/
void complete(String phoneNumber, IM800UserProfile userProfile, boolean
isContact);
/**
* Called when M800 user search is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param phoneNumber the phone number used during search
* @param error simplified error result
* @param message detail error result
*/
void error(String phoneNumber, M800PacketError error, String message);
}
Take the demo project as an example. Please refer to the class ContactApiDemoFindUserByNumFromServerActivity.java.
mFindUserManager.findM800UserByPhoneNumberFromServer(phoneNumber, new
IM800FindUserManager.FindM800UserByPhoneNumberCallback() {
@Override
public void complete(String phoneNumber, IM800UserProfile userProfile, boolean
isContact) {
//Invoked when M800 user search is finished without error.
//if userProfile is null, that mean user not found.
}
@Override
public void error(String phoneNumber, M800PacketError error, String message) {
//Invoked when M800 user search is finished with error.
}
});
1. Please note that, even if complete () invoked, please don't forget check the userProfile. If userProfile is null, that mean user not found
in server.
2. To query user by JID from server, please invoke findM800UserByJIDFromServer ().
/**
* Query an M800 user's profile by JID
from M800 server asynchronously.
*
* @param JID the unique identifier of an M800 user
* @param callback an asynchronous callback of find user result, {@link
FindM800UserByJIDCallback#complete(String, IM800UserProfile, boolean)}
*
method will be called if the request is success, otherwise {@link
FindM800UserByJIDCallback#error(String, M800PacketError, String)}
*
method will be called.
*/
void findM800UserByJIDFromServer(String JID, FindM800UserByJIDCallback callback);
/**
* Callback for use with {@link
IM800FindUserManager#findM800UserByJIDFromServer(String, FindM800UserByJIDCallback)}
to get the
request result.
*/
interface FindM800UserByJIDCallback {
/**
* Called when M800 user search is finished without error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param JID the unique identifier of an M800 user
* @param userProfile the search result, if result not found, this should be null
* @param isContact indicates whether the related user is friend or not
*/
void complete(String JID, IM800UserProfile userProfile, boolean isContact);
/**
* Called when M800 user search is finished with error.
*
* <p>This callback is called on application's main thread.</p>
*
* @param JID the unique identifier of an M800 user
* @param error simplified error result
* @param message detail error result
*/
void error(String JID, M800PacketError error, String message);
}
findUserManager.findM800UserByJIDFromServer(jid, new
IM800FindUserManager.FindM800UserByJIDCallback() {
@Override
public void complete(String JID, IM800UserProfile userProfile, boolean
isContact) {
//Invoked when M800 user search is finished without error.
//if userProfile is null, that mean user not found.
}
@Override
public void error(String JID, M800PacketError error, String message) {
//Invoked when M800 user search is finished with error.
}
});
Please note that, even if complete () invoked, please don't forget check the userProfile. If userProfile is null, that mean user not found
in server.
M800SDK will cache M800 user's profile locally, it provided a fast way to query the user profile, but the data will not auto update unless
the M800 user is current user's M800 contact and M800 roster is started, so the user profile you get from this method is not guaranteed to
contain the latest data.
/**
* Query an M800 user's profile by JID in local M800SDK database synchronously.
*
* <p>Note: M800SDK will cache M800 user's profile locally,
* but it will not update the profile data unless the M800 user is current user's
M800 contact and M800 roster is started
* (M800 roster will push contacts' change to user), so the user profile you get
from this method is not guaranteed to contain the latest data.
* This means, the user name, email...etc may not be the most updated.</p>
* <p>If you want to get the most updated user profile, please use {@link
#findM800UserByJIDFromServer(String, FindM800UserByJIDCallback)}</p>
*
* @param JID the unique identifier of an M800 user
*/
IM800UserProfile findM800UserByJIDFromLocal(String JID);
If you want to get the most updated user profile, we recommend that please see findM800UserByJIDFromServer ().
Since the above query methods are related to database query action, we recommend that, developer should invoke this method on a
background thread, thus avoid blocking the main thread process.
mFindUserManager.findM800UserByPin(pin, new
IM800FindUserManager.FindM800UserByPinCallback() {
@Override
public void complete(String pin, IM800UserProfile userProfile, boolean isContact) {
if (userProfile != null) {
// Found the user
} else {
// User not found
}
}
@Override
public void error(String pin, M800PacketError error, String message) {
// Error
}
});
mFindUserManager.findM800UsersByRecommendation(new
IM800FindUserManager.FindM800UsersCallback() {
@Override
public void complete(List<IM800UserProfile> userProfiles) {
}
@Override
public void error(M800PacketError error, String message) {
}
}, true);
You can remove a user from the recommended user list use the following API:
/**
* Remove an M800 user from the recommended user list.
*
* <p>Next time when {@link
IM800FindUserManager#findM800UsersByRecommendation(FindM800UsersCallback, boolean)}
* is called, this user will not appear in the list.</p>
*
* @param JID the unique identifier of an M800 user
* @param callback an asynchronous callback of remove user from recommendation list
result, {@link RemoveRecommendationCallback#success(String)}
*
method will be called if the request is success, otherwise {@link
RemoveRecommendationCallback#error(String, M800PacketError, String)}
*
method will be called.
*/
void removeM800UserFromRecommendation(String JID, RemoveRecommendationCallback
callback);
M800SDK.getInstance().getFindUserManager().reportM800User("JID", new
IM800FindUserManager.ReportM800UserCallback() {
@Override
public void success(String JID) {
}
@Override
public void error(String JID, M800PacketError error, String message) {
}
});
You can block or unblock an M800 user. Current user will not receive any IM or call from the blocked user.
M800SDK.getInstance().getFindUserManager().blockM800User("JID", new
IM800FindUserManager.BlockM800UserCallback() {
@Override
public void success(String JID, boolean isBlocked) {
}
@Override
public void error(String JID, M800PacketError error, String message) {
}
});
How to Implement
As a start point...
Please get an instance of IM800AccountManager from M800SDK.
/**
* Get name of current user.
*
* @return name of current user
*/
String getName();
Retrieve Status
To retrieve the status, please invoke following method.
/**
* Get status of current user.
*
* @return status of current user
*/
String getStatus();
Retrieve Gender
To retrieve the gender, please invoke following method.
/**
* Get gender of current user.
*
* @return gender of current user
*/
IM800UserProfile.Gender getGender();
Retrieve Birthday
To retrieve the birthday, please invoke following method.
/**
* Get birthday of current user.
*
* @return time(UTC) of birthday, return -1 if not defined
*/
long getBirthday();
/**
* Get email address of current user.
*
* @return email address of current user
*/
String getEmailAddress();
/**
* Get profile image url of current user.
*
* @return url of media, return null if not found.
*/
String getProfileImageUrl();
To retrieve the profile image thumbnail url, please invoke following method.
/**
* Get profile thumbnail url of current user.
*
* @return url of media, return null if not found.
*/
String getProfileImageThumbnailUrl();
/**
* Get cover image url of current user.
*
* @return url of media, return null if not found.
*/
String getCoverImageUrl();
/**
* Get caller video url of current user.
*
* @return url of media, return null if not found.
*/
String getCallerVideoUrl();
To retrieve the caller video thumbnail url, please invoke following method.
/**
* Get caller video thumbnail url of current user.
*
* @return url of media, return null if not found.
*/
String getCallerVideoThumbnailUrl();
/**
* Set name of current user.
*
* @param value name of current user
* @param callback an asynchronous callback of set profile data, {@link
UpdateUserProfileCallback#complete()} method will be called if the request is success,
otherwise {@link UpdateUserProfileCallback#error(M800PacketError, String)} method will
be called.
*/
void setName(String value, UpdateUserProfileCallback callback);
Update Status
Unlike other user profile values, user status will be cleared every time user sign-in. It is recommended that you set a default status for
user after he/she sign-up successfully.
To update the status, please invoke following method.
/**
* Set status of current user.
*
* @param value status of current user
* @param callback an asynchronous callback of set profile data, {@link
UpdateUserProfileCallback#complete()} method will be called if the request is success,
otherwise {@link UpdateUserProfileCallback#error(M800PacketError, String)} method will
be called.
*/
void setStatus(String value, UpdateUserProfileCallback callback);
Update Gender
To update the gender, please invoke following method.
/**
* Set gender of current user.
*
* @param gender status of current user
* @param callback an asynchronous callback of set profile data, {@link
UpdateUserProfileCallback#complete()} method will be called if the request is success,
otherwise {@link UpdateUserProfileCallback#error(M800PacketError, String)} method will
be called.
*/
void setGender(IM800UserProfile.Gender gender, UpdateUserProfileCallback callback);
Update Birthday
To update the birthday and the date is selected from DatePickerDialog, please invoke following method.
/**
* Set birthday of current user.
*
* @param year year of birthday
* @param monthOfYear month of birthday
* @param dayOfMonth day of birthday
* @param callback an asynchronous callback of set profile data, {@link
UpdateUserProfileCallback#complete()} method will be called if the request is success,
otherwise {@link UpdateUserProfileCallback#error(M800PacketError, String)} method will
be called.
*/
void setBirthday(int year, int monthOfYear, int dayOfMonth, UpdateUserProfileCallback
callback);
The following code show how to update the birthday. where the date is selected from DatePickerDialog.
/**
* Set email address of current user.
*
* @param value email of current user
* @param callback an asynchronous callback of set profile data, {@link
UpdateUserProfileCallback#complete()} method will be called if the request is success,
otherwise {@link UpdateUserProfileCallback#error(M800PacketError, String)} method will
be called.
*/
void setEmailAddress(String value, UpdateUserProfileCallback callback);
/**
* Set profile image of current user.
*
* @param source
media source
* @param callback file upload progress listener
*/
void setProfileImage(File source, UpdateUserProfileMediaSourceCallback callback);
/**
* Set cover image of current user.
*
* @param source
media source
* @param callback file upload progress listener
*/
void setCoverImage(File source, UpdateUserProfileMediaSourceCallback callback);
/**
* Set caller video of current user.
*
* @param source
media source
* @param callback file upload progress listener
*/
void setCallerVideo(File source, UpdateUserProfileMediaSourceCallback callback);
/**
* Remove profile image of current user.
*
* @param callback remove file progress listener
*/
void deleteProfileImage(DeleteUserProfileMediaSourceCallback callback);
/**
* Remove cover image of current user.
*
* @param callback remove file progress listener
*/
void deleteCoverImage(DeleteUserProfileMediaSourceCallback callback);
/**
* Remove caller video of current user.
*
* @param callback remove file progress listener
*/
void deleteCallerVideo(DeleteUserProfileMediaSourceCallback callback);
User Preference
Introduction
The User Preference module in the m800SDK provides functionality to modify the user preference, and sync the related data to server.
How to Implement
As a start point...
Please get an instance of IM800UserPreference from M800SDK.
/**
* Return a user preference - language
*
* @param defaultValue it default value will return if a null value is associated with
this field.
* @return the value associated with this field, or defaultValue if no valid value is
currently mapped to this field.
*/
IM800Management.M800Language getLanguage(IM800Management.M800Language defaultValue);
/**
* Store a user preference - language
*
* <p>After update, it will update the related user preference to server
automatically. Client side also can use this value to setup corresponding UI.</p>
*
* @param language which is supported by M800 SDK
*/
void setLanguage(IM800Management.M800Language language);
Recommendation
The recommendation preference is referring to the feature of finding M800 recommended users in Find User Module,
To retrieve the current setting, please invoke the following method:
/**
* Get the current preference setting of recommendation of users.
* @return {@code true} if this preference enabled.
*/
boolean isRecommendationEnabled();
/**
* Enable finding M800 recommendated users
* @param enable {@code true} the set this preference enabled.
*/
void enableRecommendation(boolean enable);
/**
* Get the current preference setting of enable finding users by Pin/Phone.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isFindUsersByPinPhoneEnabled();
/**
* Enable finding users by Pin/Phone
* @param enable {@code true} the set this preference enabled.
*/
void enableFindUsersByPinPhone(boolean enable);
/**
* Get the current preference setting of enable finding users by location.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isFindUsersByLocationEnabled();
/**
* Enable finding users by location
* @param enable {@code true} the set this preference enabled.
*/
void enableFindUsersByLocation(boolean enable);
/**
* Get the current preference setting of showing the user's video callerId to others.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isShowingMyCallerId();
/**
* Enable showing the user's video callerId to others
* @param show {@code true} the set this preference enabled.
*/
void showMyCallerId(boolean show);
/**
* Get the current preference setting of showing the other's video callerId to the
user.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isShowingOthersCallerId();
/**
* Enable showing other's video callerId to the user.
* @param show {@code true} the set this preference enabled.
*/
void showOthersCallerId(boolean show);
Presence
The presence preference is referring to the feature of sending online/offline state in Connect Module,
After enabling this preference, other users will see your last online time.
To retrieve the current setting, please invoke the following method:
/**
* Get the current preference setting of sharing the user's presence to others.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isSharingMyPresence();
/**
* Enable sharing the user's presence to others.
* @param share {@code true} the set this preference enabled.
*/
void shareMyPresence(boolean share);
Displayed Receipt
The displayed receipt preference is referring to the feature of sending displayed receipt of an incoming message in Message Module,
After enabling this preference, you will be able to send the displayed receipt per incoming message.
To retrieve the current setting, please invoke the following method:
/**
* Get the current preference setting of sending displayed receipt of incoming
messages.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isDisplayedReceiptEnabled();
/**
* Enable sending displayed receipt of incoming messages.
* <p/>
* Please note that developers have to handle the related business logic by
themselves.<br/>
* For example, check {@link #isDisplayedReceiptEnabled()} before sending the
displayed receipt of an incoming message.
* @param enable {@code true} means a displayed receipt should be sent for every
message which has been displayed to the user.
*/
void enableDisplayedReceipt(boolean enable);
Message notifications
The message notifications preference is referring to the feature of receiving incoming message notifications from GCM/ JPush/ M800Server,
After enabling this preference, you will receive notifications of incoming messages.
To retrieve the current setting, please invoke the following method:
/**
* Get the current preference setting of receiving incoming message notifications.
* @return {@code true} if this preference enabled. Default value, true.
*/
boolean isMessageNotificationEnabled();
/**
* Enable receiving incoming message notifications.
* @param enable {@code true} the set this preference enabled.
*/
void enableMessageNotification(boolean enable);
/**
* Register a listener that listeners events of all user preference update.
*
* @param listener a listener implements {@link IM800UserPreferenceListener}
* @throws NullPointerException if listener is null
*/
void addListener(IM800UserPreferenceListener listener);
/**
* Callback to monitor the update event of user preference.
*/
interface IM800UserPreferenceListener {
/**
* This method is invoked when user preference[language] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param language The updated language.
*/
void onLanguageUpdated(IM800Management.M800Language language);
/**
* This method is invoked when user preference[Recommendation] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param enabled provides the latest preference setting.
*/
void onRecommendationEnabled(boolean enabled);
/**
* This method is invoked when user preference[FindUsersByPinPhone] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param enabled provides the latest preference setting.
*/
void onFindUsersByPinPhoneEnabled(boolean enabled);
/**
* This method is invoked when user preference[FindUsersByLocation] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param enabled provides the latest preference setting.
*/
void onFindUsersByLocationEnabled(boolean enabled);
/**
* This method is invoked when user preference[ShowMyCallerId] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param isShowing provides the latest preference setting.
*/
void onShowingMyCallerId(boolean isShowing);
/**
* This method is invoked when user preference[ShowOthersCallerId] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param isShowing provides the latest preference setting.
*/
void onShowingOthersCallerId(boolean isShowing);
/**
* This method is invoked when user preference[ShareMyPresence] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param isSharing provides the latest preference setting.
*/
void onSharingMyPresence(boolean isSharing);
/**
* This method is invoked when user preference[SendDisplayedReceipt] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param enabled provides the latest preference setting.
*/
void onDisplayedReceiptEnabled(boolean enabled);
/**
* This method is invoked when user preference[ReceiveMessageNotification] is updated.
* <p>
* This callback is invoked on {@link android.app.Application}'s main thread.
*
* @param enabled provides the latest preference setting.
*/
void onMessageNotificationEnabled(boolean enabled);
/**
* Called when sync status changed.
*
* <p>This callback is called on application's main thread.</p>
*
* @param isSyncing Indicates whether user preference is synced with server.
*/
We recommend that you keep the reference object of the listener, since developer needs it to stop related monitoring.
To stop monitoring User Preference Update Activity, please invoke removeListener() to stop monitor User Preference update activity.
/**
* Unregister a listener.
*
* @param listener an user preference listener previously registered
* @throws NullPointerException if listener is null
*/
void removeListener(IM800UserPreferenceListener listener);
To stop all User Preference Update Activity monitoring, please invoke clearListeners() to stop monitor User Preference update activity.
/**
* Unregister all user preference listeners.
*/
void clearListeners();
/**
* Indicates whether user preference is synced with server.
*
* @return whether user preference is synced with server
*/
boolean isDataSynced();
To check whether the user preference synchronization is in progress. please invoke following method.
/**
* Indicates whether user preference synchronization task is running or not.
*
* @return whether user preference synchronization task is running or not.
*/
boolean isDataSyncing();
To check last time of user preference synchronization. please invoke following method.
/**
* Retrieve the last success sync time.
*
* @return last success sync time, return -1 if never synced yet.
*/
long getLastSyncTime();
/**
* Request to start user preference synchronization task.
* <p>
*
If synchronization task is executed once, and force is not set to true, no
synchronization task will be executed.
*
Only one synchronization task will be executed at one time, no duplicate
request allowed.
* </p>
*
* @param force force update
*/
void syncData(boolean force);