Advanced intégration
MQTT Chat can be customized to best suit your application need.

Settings

MQTTChat GUI already offers a basic interface to allow users to change chat settings.
If you want to use gloobal settings. or integrate chat settings into your main settings activity. you can proceed as follows:
  1. 1.
    Remove settings button from GUI.
1
Mqttchat.getmInstance().getMySettings().setShowSettingsIcon(false);
Copied!
2. Change MQTTChat Settings using Code.
  • Enable/Disable sound notifications:
1
Mqttchat.getmInstance().getMySettings().setSoundAlerts(true);
2
Mqttchat.getmInstance().getMySettings().isSoundAlerts();
Copied!
  • Enable/Disable Audio calls:
1
Mqttchat.getmInstance().getMySettings().setAcOk(true);
2
Mqttchat.getmInstance().getMySettings().isAcOk()
Copied!
  • Enable/Disable Video calls:
1
Mqttchat.getmInstance().getMySettings().setVcOk(false);
2
Mqttchat.getmInstance().getMySettings().isVcOk()
Copied!
  • Enable/Disable FCM Notifications :
If true, an android notification will be displayed to the user if a message is received and the app is closed.
1
Mqttchat.getmInstance().getMySettings().setNotification(true);
2
Mqttchat.getmInstance().getMySettings().isNotifications();
Copied!
3. Change user status programmatically.
Status can be : Presence.ONLINE or Presence.BUSY. Second parameter can be : null or Callback object.
1
Mqttchat.getmInstance().getMyPresence().setUserStatus(Presence.ONLINE, null);
Copied!

MQTT Notifications

Before we see how to retrieve and view MQTT notifications. Click here to learn how to send notifications from Server using REST API.
To retrieve MQTT notifications sent from the server to android Application two cases may arise:

Application is on foreground

In this case android application is on foreground and connection with the MQTT server is established.
So you can catch event using MqttChatListener already seen here.
1
App.getInstance().addChatiListener(new myChatiListener() {
2
@Override
3
public void onReceiveNotification(Notification notification) {
4
/** notification received here **/
5
}
6
});
7
Copied!

Application is closed or in background

If application is closed or application is in background. in this case notification cannot be sent by MQTT and then will be sent with FCM provided FCM feature is enabled.
So you can catch event using MqttChatFCMListener already seen here.
1
Mqttchat.getmInstance().addMqttchatFCMListener(new MqttChatFCMListener() {
2
@Override
3
public void onReceiveFCMNotification(boolean notificationsSettingEnabled, int toUserId, Notification notification) {
4
/** notification received here **/
5
}
6
});
7
Copied!
notificationsSettinEnabled: indicates whether or not user accepts FCM notifications for offline messages in chat settings. If you want to consider it also to show notifications or you can simply ignore it.
Therefore to receive notifications regardless of the application is in the foreground or closed. it is necessary to implement the two senarios.

Friends feature

Search feature

Last modified 2mo ago