The Methods below are available for One-on-one chat:
Method | Description |
---|---|
setStatus | Sets a status for logged-in user |
setStatusMessage | Sets a status message for logged-in user |
getUserInfo | Allows logged-in user to pull details of other user |
getOnlineUsers | Gets list of online users from the server |
sendMessage | Allows logged-in user to send a message to other user |
sendImage | Allows logged-in user to send an image to other user |
sendVideo | Allows logged-in user to send a video to other user |
sendAudioFile | Allows logged-in user to send an audio to other user |
sendSticker | Allows logged-in user to send a sticker to currently opened group chat |
sendFile | Allows logged-in user to send a file |
getChatHistory | Gets chat history with another user |
broadcastMessage | Allows logged-in Send a text message to more than one user |
isTyping | Sends the typing notification to other users. This feature works only with CometService |
sendDeliverdReceipt | Sends the message delivery receipt to the sender of the message |
sendReadReceipt | Sends the message read receipt to the sender of the message |
getAllAnnouncements | Pulls the announcements from server |
blockUser | Blocks a user |
getBlockedUserList | Gets the list of blocked users |
unblockUser | Unblocks a user |
setTranslateLanguage | Set the language for real time translation |
getPluginInfo | Gets the details of the enabled plugins |
isLoggedIn | Return true for when user is logged-in |
isCometChatInstalled | Checks if CometChat is installed at given URL |
setDevelopmentMode | Sets the development mode |
setStatus
CometChat allows you to set the status for your profile. You can set any one of the “Available”, “Busy”, “Invisible”, “Offline” status. Method Signature:
setStatus(StatusOption statusOption, Callbacks callback)
Example:
cometChat.setStatus(StatusOption.BUSY, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
statusOption | status to set on profile |
callback | success and failure callbacks |
Response for successCallback:
{
message: "status updated"
}
setStatusMessage
Method Signature:
setStatusMessage(String statusMessage, Callbacks callback)
Example:
cometChat.setStatusMessage("What a beautiful day!!", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
statusMessage | status message to set on profile |
callback | success and failure callbacks |
Response for successCallback:
{
message: "status message updated"
}
getUserInfo
Allows logged-in user to fetch details of any user. Method Signature:
getUserInfo(String userId, Callbacks callback)
Example:
cometChat.getUserInfo("12", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
userId | recipient’s user id |
callback | success and failure callbacks |
Response for successCallback:
{
"id": "12",
"n": "Jon Snow",
"l": "",
"d": "0",
"a": "",
"s": "offline",
"m": "Wonderful day",
"ch": "cc735e0970a1e82bb6738e59b881cb23",
ls": "1451218483",
"lstn": "0"
}
getOnlineUsers
You can get the user list whenever you require. Method Signature:
getOnlineUsers(Callbacks callback)
Example:
getOnlineUsers(new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
callback | success and failure callbacks |
Response for successCallback:
{
{
"id": "1","n": "User1", "a": "avatar.png", "d": "1", "s": "available","m": "I'm available"
},
{
"id": "2", "n": "User2", "a": "avatar.png", "d": "1", "s": "available","m": "I'm available"
}
}
sendMessage
Allows logged-in user to send message to other users. Method Signature:
sendMessage(long localId, String toId, String message, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendMessage(50, "15", "Hi! How are you?", false, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | a parameter which is returned to you with the response to keep track of the status of the message sent |
toId | recipient’s user id |
message | text message |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 71,
"localmessageid": 50,
"m": "Hi! How are you?"
}
sendImage
Allows logged-in user to send an image using Bitmap or filepath
Sending a Bitmap image
Method Signature:
sendImage(long localId, Bitmap bitmap, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendImage(101, bitmap, "15", false, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
bitmap | bitmap of the image |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid":101,
"original_file": "[email protected]"
}
Sending an image using file path
Method Signature:
sendImage(long localId,File imageFile, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendImage(201, "/storage/sdcard0/image.jpg", "15", false, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
imageFile | image file from storage |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid":201,
"original_file": "/storage/sdcard0/image.jpg"
}
sendVideo
Allows logged-in user to send a video Method Signature:
sendVideo(long localId, String filePath, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendVideo(301, "/storage/sdcard0/video1.mp4", "15", false, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
filepath | path of the file |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid":301,
"original_file": "/storage/sdcard0/video1.mp4",
}
sendAudioFile
Allows logged-in user to send an audio file or recorded audio notes
Method Signature:
sendAudioFile(long localId,File audioFile, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendAudioFile(501,new File("/storage/sdcard0/audio1.aac"), "15", false, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
audioFile | audio file from storage |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid":501,
"original_file": "/storage/sdcard0/audio1.aac"
}
sendSticker
Allows the user to send a sticker.
Method signature:
sendSticker(long localId, String message, String id, boolean isGroup, Callbacks callback)
Example:
cometChat.sendSticker(601,"bear_2", "15", false, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
message | Sticker name |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
sendFile
Allows the logged in user to send a file.
Method Signature:
sendFile(long localId, File file, String id, boolean isGroup, Callbacks callback)
Example:
cometChat.sendFile(701,file, "15", false, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
file | file to be sent |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
getChatHistory
Allows logged-in user to get the previous message
Method Signature:
getChatHistory(Long userId, Long messageId, Callbacks callback)
Example:
cometChat.getChatHistory(10, 102, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
userId | recipient’s user id |
messageId | last message id |
callback | success and failure callbacks |
Response for successCallback:
{
history : [
{
from = 14; id = 4843; message = "HI"; "message_type" = 10; old = 1; self = 1; sent = 1429771974000;
},
{
from = 14; id = 4844; message = "Hello"; "message_type" = 10; old = 1; self = 1; sent = 1429772345000;
},
.
.
]
}
broadcastMessage
Allows logged-in user to send a message to more than one users Method Signature:
broadcastMessage(String message, JSONArray users, Callbacks callbacks)
Example:
JSONArray users = new JSONArray();
users.put(1);
users.put(2);
users.put(3);
cometChat.broadcastMessage("HI", users, new Callbacks(){
@Override
public void successCallback(JSONObject response){
}
@Override
public void failCallback(JSONObject response){
}
});
Arguments:
Argument | Description |
---|---|
message | message text |
users | recipient user’s array |
callback | success and failure callbacks |
Response for successCallback:
{
[
{ "id": 71, "to":1, "m": "Hi! How are you?" },
{ "id": 72, "to":2, "m": "Hi! How are you?" },
{ "id": 73, "to":3, "m": "Hi! How are you?" }
]
}
isTyping
Allows logged-in user to send an typing notification Method Signature:
isTyping(boolean istyping, String channel, Callbacks callbacks)
Example:
cometChat.isTyping(true, "49086e3ef2d52d104fa0bc7cade215cf", new Callbacks(){
@Override
public void successCallback(JSONObject response){
}
@Override
public void failCallback(JSONObject response){
}
});
Arguments:
Argument | Description |
---|---|
isTyping | This is boolean value , pass true when you start typing, pass false when you stop typing |
channel | This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService |
callback | Will result in fail callback if CometService is not enabled for your site |
sendDeliverdReceipt
Allows logged-in user to notify message delivery to the sender. Method Signature:
sendDeliverdReceipt(String messageId, String channelId, Callbacks callbacks)
Example:
cometChat.sendDeliverdReceipt("5", "49086e3ef2d52d104fa0bc7cade215cf", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
messageId | id for the received message |
channelId | This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService |
callback | Will result in fail callback if CometService is not enabled for your site |
sendReadReceipt
Allows logged-in user to notify to the sender that the message has been read. Method Signature:
sendReadReceipt(String messageId, String channelId, Callbacks callbacks)
Example:
cometChat.sendReadReceipt("5", "49086e3ef2d52d104fa0bc7cade215cf", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
messageId | id for the received message |
channelId | This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService |
callback | Will result in fail callback if CometService is not enabled for your site |
getAllAnnouncements
Gets all the announcements added by CometChat admin. Method Signature:
getAllAnnouncements(Callbacks callback)
Example:
cometChat.getAllAnnouncements(new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
callback | success and failure callbacks |
Response for successCallback:
{
"_2":
{ "id": "2", "m": "Test 2", "t": "1416576762"},
"_1":
{ "id": "1", "m": "Announcements test","t": "1416576743" }
}
blockUser
Allows logged-in user to block a user Method Signature:
blockUser(String toId, Callbacks callback)
Example:
cometChat.blockUser("15", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
toId | recipient id to be block |
callback | success and failure callbacks |
Response for successCallback:
{
"id": "15"
}
Description:
Response Proprty | Description |
---|---|
id | userid of blocked user |
getBlockedUserList
Allows logged-in user to send an audio file or recorded audio notes Method Signature:
getBlockedUserList(Callbacks callback)
Example:
cometChat.getBlockedUserList(new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Response for successCallback:
{
"73": { "id": "73", "name": "user73" },
"700": { "id": "70", "name": "user70" }
}
Description:
Response Property | Description |
---|---|
id | userid of blocked user |
name | username of blocked user |
unblockUser
Allows logged-in user to unblock a user Method Signature:
unblockUser(String toId, Callbacks callback)
Example:
cometChat.unblockUser("15", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
toId | recipient id to be unblock |
callback | success and failure callbacks |
Response for successCallback:
{
"id": "15"
}
Description:
Response Proprty | Description |
---|---|
id | userid of unblocked user |
setTranslateLanguage
Allows logged-in user to set a language for real time translation Method Signature:
setTranslateLanguage(Languages ENUM, Callbacks callback)
Example:
cometChat.setTranslateLanguage(Languages.Spanish, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
ENUM | a value from Languages enum |
Callbacks | Callback Methods |
Response for successCallback:
{
"Selected language": "Spanish"
}
getPluginInfo
Gets the enabled status for the plugins Method Signature:
getPluginInfo(Callbacks callback)
Example:
cometChat.getPluginInfo(new Callbacks(){
@Override
public void successCallback(JSONObject response){
}
@Override
public void failCallback(JSONObject response){
}
});
Response for successCallback:
{
"avchat_enabled": "1",
"audiochat_enabled": "1",
"createchatroom_enabled": "1",
"blockuser_enabled": "0",
"mediasharing_enabled": "1",
"chatroom_mediasharing_enabled": "1",
"realtime_translate_enabled": "0"
}
isLoggedIn
Return true if user has logged-in Method Signature:
isLoggedIn()
Example:
cometChat.isLoggedIn();
isCometChatInstalled
Checks whether CometChat is installed on your website Method Signature:
isCometChatInstalled(String url, Callbacks callback)
Example:
cometChat.isCometChatInstalled("http://www.example.com", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
url | url of your CometChat directory |
callback | success and failure callbacks |
Response for successCallback:
{
cometchat_url: "http://www.example.com/cometchat/"
}
setDevelopmentMode
Allows developer turn on/off the development. The request/responses will be shown in the log when development mode is on. Method Signature:
setDevelopmentMode(Boolean flag)
Example:
cometChat.setDevelopmentMode(true);
Arguments:
Argument | Description |
---|---|
flag | turn on/off development mode |