Android: How do i get user online/offline status using quickblox? - android

I am not able to get the user online/offline status in QuickBlox. I have tried using QBRoster.
The function that I have written to get user presence.
private void subscribeUserForStatus(ArrayList<Integer> mQBUserList) {
if (QBChatService.getInstance().getRoster() != null) {
mQbRoster = QBChatService.getInstance().getRoster(
QBRoster.SubscriptionMode.mutual, this);
mQbRoster.addRosterListener(this);
for (Integer mId : mQBUserList) {
try {
if (mQbRoster.contains(mId)) {
mQbRoster.subscribe(mId);
} else {
mQbRoster.createEntry(mId, null);
}
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
Log.e("Crash on subscription", e.getMessage());
}
}
}
}

int userID = 45;
QBPresence presence = chatRoster.getPresence(userID);
if (presence == null) {
// No user in your roster
return;
}
if (presence.getType() == QBPresence.Type.online) {
// User is online
}else{
// User is offline
}
This can also help you :
QBRosterListener rosterListener = new QBRosterListener() {
#Override
public void entriesDeleted(Collection<Integer> userIds) {
}
#Override
public void entriesAdded(Collection<Integer> userIds) {
}
#Override
public void entriesUpdated(Collection<Integer> userIds) {
}
#Override
public void presenceChanged(QBPresence presence) {
}
};
This link is helpful :
https://quickblox.com/developers/Android_XMPP_Chat_Sample

The above answer is correct and you can use it like this
QBRosterListener rosterListener = new QBRosterListener() {
#Override
public void entriesDeleted(Collection<Integer> userIds) {
}
#Override
public void entriesAdded(Collection<Integer> userIds) {
}
#Override
public void entriesUpdated(Collection<Integer> userIds) {
}
#Override
public void presenceChanged(QBPresence presence) {
if (presence == null) {
// No user in your roster
return;
}
if (presence.getType() == QBPresence.Type.online) {
// User is online
}else{
// User is offline
}
}
};

You can use this code
Roster roster = xmppConnection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
Presence presence;
for(RosterEntry entry : entries) {
presence = roster.getPresence(entry.getUser());
System.out.println(entry.getUser());
System.out.println(presence.getType().name());
System.out.println(presence.getStatus());
}

Related

How to update Message Activity without refresh?

I am making app where users can chat with each other in app , but the problem is when user send message it doesn't appear in chat box until user refresh the activity . how can i update chat without refresh ?
this is my code
ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class);
subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<Message>() {
#Override
public void onEvent(ParseQuery<Message> query, final Message message) {
// HANDLING create event
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
mList.add(message);
msgAdapter.notifyDataSetChanged();
show_message.scrollToPosition(mList.size() - 1);
}
});
public void onEvent(ParseQuery<Message> query, Message message) {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
mList.clear();
getData();
}
});
public void onClick(View v) {
Message msg = parseMessenger.SendMessage(send_txt.getText().toString(), null, new SaveCallback() {
#Override
public void done(ParseException e) {
send_txt.setText("");
}
}, new SendCallback() {
#Override
public void done(ParseException e) {
}
});
if (mList == null) {
mList = new ArrayList<Message>();
}
}
});
getData();
private void getData() {
ParseQuery<Message> messageFromQuery = Message.getAllMessage();
messageFromQuery.whereEqualTo(Message.COL_USER_FROM, userFrom);
messageFromQuery.whereEqualTo(Message.COL_USER_TO, userTo);
ParseQuery<Message> messageToQuery = Message.getAllMessage();
messageToQuery.whereEqualTo(Message.COL_USER_TO, userFrom);
messageToQuery.whereEqualTo(Message.COL_USER_FROM, userTo);
List<ParseQuery<Message>> messageQueries = new ArrayList<ParseQuery<Message>>();
messageQueries.add(messageFromQuery);
messageQueries.add(messageToQuery);
ParseQuery<Message> messageQuery = ParseQuery.or(messageQueries);
messageQuery.orderByAscending("createdAt");
messageQuery.findInBackground(new FindCallback<Message>() {
#Override
public void done(List<Message> messages, ParseException e) {
if (messages != null) {
mList.clear();
mList.addAll(messages);
msgAdapter = new MsgAdapter(requireContext(), mList, userTo.getObjectId(), userTo);
show_message.setAdapter(msgAdapter);
show_message.scrollToPosition(mList.size() - 1);
}
}
});
}
i can add auto refresh when send button is clicked but i don't want so , it will not look nice when users use it .. please help

How can I invite a user to a newly created private chat channel using the Twilio?

I have created a private channel, and joined the channel. I like to invite another user to join that channel and chat. To be clear, this should be a chat between two members only.
public class MainActivity extends AppCompatActivity {
/*
Change this URL to match the token URL for your Twilio Function
*/
final static String SERVER_TOKEN_URL = "https://example.com/twilio/token/";
final static String MY_CHANNEL_NAME = "testchat1234567810";
final static String TAG = "TwilioChat";
// Update this identity for each individual user, for instance after they login
private String mIdentity ;
private String accessToken;
private RecyclerView mMessagesRecyclerView;
private MessagesAdapter mMessagesAdapter;
private ArrayList<Message> mMessages = new ArrayList<>();
private EditText mWriteMessageEditText;
private Button mSendChatMessageButton;
private ChatClient mChatClient;
private Channel mGeneralChannel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMessagesRecyclerView = (RecyclerView) findViewById(R.id.messagesRecyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
// for a chat app, show latest at the bottom
layoutManager.setStackFromEnd(true);
mMessagesRecyclerView.setLayoutManager(layoutManager);
mMessagesAdapter = new MessagesAdapter();
mMessagesRecyclerView.setAdapter(mMessagesAdapter);
mWriteMessageEditText = (EditText) findViewById(R.id.writeMessageEditText);
mSendChatMessageButton = (Button) findViewById(R.id.sendChatMessageButton);
mSendChatMessageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
createOrJoinChannel();
if (mGeneralChannel != null) {
String messageBody = mWriteMessageEditText.getText().toString();
Message.Options options = Message.options().withBody(messageBody);
// mGeneralChannel.getMembers().add();
Members members = mGeneralChannel.getMembers();
if (members != null) {
ArrayList<Member> list = (ArrayList<Member>) members.getMembersList();
for (int i = 0; i < list.size(); i++) {
Log.i(TAG, "member " + i + list.get(i).getIdentity());
}
}
mGeneralChannel.getMembers().inviteByIdentity("user1#gmail.com", new StatusListener() {
#Override
public void onSuccess() {
Log.d(TAG, "User Invited on send!");
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG, "chats: inviting user" + errorInfo.getMessage());
}
});
mGeneralChannel.getMembersCount(new CallbackListener<Long>() {
#Override
public void onSuccess(Long aLong) {
Log.e("member count >>", aLong + "");
}
});
mGeneralChannel.getMessages().sendMessage(options, new CallbackListener<Message>() {
#Override
public void onSuccess(Message message) {
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
Log.d(TAG, "Message created");
// need to modify user interface elements on the UI thread
mWriteMessageEditText.setText("");
}
});
}
});
}
}
});
retrieveAccessTokenfromServer();
}
private void retrieveAccessTokenfromServer() {
String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
Log.e("deviceid >>",deviceId);
String tokenURL = SERVER_TOKEN_URL + deviceId;
Ion.with(this)
.load(tokenURL)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
#Override
public void onCompleted(Exception e, JsonObject result) {
Log.e("result >>", result.toString() + "");
if (e == null) {
mIdentity = result.get("identity").getAsString();
accessToken = result.get("token").getAsString();
setTitle(mIdentity);
ChatClient.Properties.Builder builder = new ChatClient.Properties.Builder();
// ChatClient.setLogLevel(Log.VERBOSE);
ChatClient.Properties props = builder.createProperties();
ChatClient.create(MainActivity.this, accessToken, props, mChatClientCallback);
} else {
Toast.makeText(MainActivity.this,
R.string.error_retrieving_access_token, Toast.LENGTH_SHORT)
.show();
}
}
});
}
private CallbackListener<ChatClient> mChatClientCallback =
new CallbackListener<ChatClient>() {
#Override
public void onSuccess(ChatClient chatClient) {
mChatClient = chatClient;
// createOrJoinChannel();
// loadChannels();
Log.d(TAG, "Success creating Twilio Chat Client");
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.e(TAG, "Error creating Twilio Chat Client: " + errorInfo.getMessage());
}
};
private void createOrJoinChannel() {
//Only SID or unique name of channel can be supplied as parameter
mChatClient.getChannels().getChannel(MY_CHANNEL_NAME, new CallbackListener<Channel>() {
#Override
public void onSuccess(Channel channel) {
if (channel != null) {
if (channel.getStatus() == Channel.ChannelStatus.JOINED) {
// already in the channel, load the messages
mGeneralChannel = channel;
mGeneralChannel.addListener(mDefaultChannelListener);
} else if (channel.getStatus() == Channel.ChannelStatus.NOT_PARTICIPATING) {
// already in the channel, load the messages
mGeneralChannel = channel;
mGeneralChannel.addListener(mDefaultChannelListener);
} else {
// join the channel
joinChannel(channel);
}
} else {
Log.i(TAG, "Error occurred in getting channel");
}
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG, "Error retrieving channel: " + errorInfo.getMessage());
createChannel();
}
});
}
private void joinChannel(final Channel channel) {
Log.i(TAG, "inside join channel" + channel.getUniqueName());
Log.i(TAG, "channel status: " + channel.getStatus());
Members members = channel.getMembers();
if (members != null) {
ArrayList<Member> list = (ArrayList<Member>) members.getMembersList();
for (int i = 0; i < list.size(); i++) {
Log.i(TAG, "member " + i + list.get(i).getIdentity());
}
} else {
Log.i(TAG, "null object"); //Getting this even when I get
//"Member already exists" error
}
channel.join(new StatusListener() {
#Override
public void onSuccess() {
mGeneralChannel = channel;
mGeneralChannel.addListener(mDefaultChannelListener);
}
#Override
public void onError(ErrorInfo errorInfo) {
//Error joining channel: Member already exists
Log.i(TAG, "Error joining channel: " + errorInfo.getMessage());
}
});
}
private void createChannel() {
mChatClient.getChannels().createChannel(MY_CHANNEL_NAME,
Channel.ChannelType.PUBLIC, new CallbackListener<Channel>() {
#Override
public void onSuccess(final Channel channel) {
if (channel != null) {
/* channel.getMembersCount(new CallbackListener<Long>() {
#Override
public void onSuccess(Long aLong) {
Log.e("member count >>",aLong+"");
}
});*/
channel.getMembers().inviteByIdentity("user1#gmail.com", new StatusListener() {
#Override
public void onSuccess() {
Log.d(TAG, "User Invited!");
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG, "chats: inviting user" + errorInfo.getMessage());
}
});
channel.join(new StatusListener() {
#Override
public void onSuccess() {
}
});
setUniqueNameAndJoin(channel);
}
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG, "chats: " + "Unique name could not be set: " + errorInfo.getMessage());
}
});
}
private void setUniqueNameAndJoin(final Channel channel) {
channel.setUniqueName(MY_CHANNEL_NAME, new StatusListener() {
#Override
public void onSuccess() {
Log.i(TAG, "channel with unique name created " + channel.getUniqueName());
joinChannel(channel);
}
#Override
public void onError(ErrorInfo errorInfo) {
super.onError(errorInfo);
}
});
}
private ChannelListener mDefaultChannelListener = new ChannelListener() {
#Override
public void onMessageAdded(final Message message) {
Log.d(TAG, "Message added");
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
// need to modify user interface elements on the UI thread
mMessages.add(message);
mMessagesAdapter.notifyDataSetChanged();
}
});
}
#Override
public void onMessageUpdated(Message message, Message.UpdateReason updateReason) {
Log.d(TAG, "Message updated: " + message.getMessageBody());
}
#Override
public void onMessageDeleted(Message message) {
Log.d(TAG, "Message deleted");
}
#Override
public void onMemberAdded(Member member) {
Log.d(TAG, "Member added: " + member.getIdentity());
}
#Override
public void onMemberUpdated(Member member, Member.UpdateReason updateReason) {
Log.d(TAG, "Member updated: " + member.getIdentity());
}
#Override
public void onMemberDeleted(Member member) {
Log.d(TAG, "Member deleted: " + member.getIdentity());
}
#Override
public void onTypingStarted(Channel channel, Member member) {
Log.d(TAG, "Started Typing: " + member.getIdentity());
}
#Override
public void onTypingEnded(Channel channel, Member member) {
Log.d(TAG, "Ended Typing: " + member.getIdentity());
}
#Override
public void onSynchronizationChanged(Channel channel) {
}
};
class MessagesAdapter extends RecyclerView.Adapter<MessagesAdapter.ViewHolder> {
class ViewHolder extends RecyclerView.ViewHolder {
public TextView mMessageTextView;
public ViewHolder(TextView textView) {
super(textView);
mMessageTextView = textView;
}
}
public MessagesAdapter() {
}
#Override
public MessagesAdapter
.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
TextView messageTextView = (TextView) LayoutInflater.from(parent.getContext())
.inflate(R.layout.message_text_view, parent, false);
return new ViewHolder(messageTextView);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Message message = mMessages.get(position);
String messageText = String.format("%s: %s", message.getAuthor(), message.getMessageBody());
holder.mMessageTextView.setText(messageText);
}
#Override
public int getItemCount() {
return mMessages.size();
}
}
}
And also, I need to accept the invite. How it can be done?

using Rxjava with retrofit and realm

i want to use the cached data in realm then update the data from server using retrofit. i managed that by the following:
public void getNotifications() {
Observable.concat(getCashedNotifications(), downloadNotification())
.subscribe(new Action1<List<Notification>>() {
#Override
public void call(List<Notification> notifications) {
setSize(notifications.size() + "");
}
});
}
private Observable<List<Notification>> getCashedNotifications() {
return Observable.just(mRealm.copyFromRealm(mRealm.where(Notification.class).findAll()));
}
private Observable<List<Notification>> downloadNotification() {
return mApiHandler.createRetrofitService(NotificationServices.class)
.getNotificationByUser(10)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(new Action1<NotificationResponse>() {
#Override
public void call(final NotificationResponse notificationResponse) {
setLoading(false);
mRealm.executeTransactionAsync(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
realm.copyToRealmOrUpdate(notificationResponse.getResult().getData().getNotifications());
}
});
}
})
.map(new Func1<NotificationResponse, List<Notification>>() {
#Override
public List<Notification> call(NotificationResponse notificationResponse) {
if (notificationResponse.getResult() != null) {
return notificationResponse.getResult().getData().getNotifications();
} else {
return new ArrayList<>();
}
}
});
}
my problem is to get the current status like :
1- if there is no data in realm show progress
2- if there is no data and no network show error dialog
3- if there is data in realm and no network show the data from realm only
4- if there is no data in realm and no data from retrofit show no data state
any idea how to know the resuslts from concat are from ? (retrofit or realm)
what i ended up with is to edit the getNotifications method to the following
public void getNotifications() {
setNoData(false);
setLoading(false);
if (ConectivityUtils.isDeviceConnectedToNetwork(mContext)) {
if (mRealm.where(Notification.class).count() > 0) {
Observable.concat(getCashedNotifications(), downloadNotification())
.subscribe(new Action1<List<Notification>>() {
#Override
public void call(List<Notification> notifications) {
setSize(notifications.size() + "");
}
});
} else {
// show progress
setLoading(true);
downloadNotification().subscribe(new Action1<List<Notification>>() {
#Override
public void call(List<Notification> notifications) {
setLoading(false);
if (notifications.size() > 0) {
setSize(notifications.size() + "");
} else {
// no data in realm and retrofit
setNoData(true);
setErrorMessage("No data");
}
}
});
}
} else {
if (mRealm.where(Notification.class).count() > 0) {
getCashedNotifications().subscribe(new Action1<List<Notification>>() {
#Override
public void call(List<Notification> notifications) {
setSize(notifications.size() + "");
}
});
} else {
//show no network
setNoData(true);
setErrorMessage("No Network");
}
}
}
but i believe that there is better and cleaner solution than this

feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas smack android

I am trying to develop a chat application but instead of Google message service I tried writing xmmp node server.
I am able to login in to server.But getting message saying feature not implemented.
<iq to='359648069251166#10.10.25.126/Smack' id='cu03M-5' type='error'><error type='cancel'><feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
android code
final TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setServiceName(IPADRESS)
.setHost(IPADRESS)
.setPort(5222)
.build();
AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
conn2.setPacketReplyTimeout(1000);
SmackConfiguration.DEBUG = true;
conn2.connect();
conn2.addConnectionListener(new ConnectionListener() {
#Override
public void connected(XMPPConnection connection) {
}
#Override
public void authenticated(XMPPConnection connection, boolean resumed) {
}
#Override
public void connectionClosed() {
}
#Override
public void connectionClosedOnError(Exception e) {
}
#Override
public void reconnectionSuccessful() {
}
#Override
public void reconnectingIn(int seconds) {
}
#Override
public void reconnectionFailed(Exception e) {
}
});
conn2.addAsyncPacketListener(new PacketListener() {
#Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
if (packet != null) {
Log.d("stanza", "received" + packet.toXML());
Toast.makeText(getApplicationContext(), packet.toXML(), Toast.LENGTH_LONG).show();
}
}
}, new PacketFilter() {
#Override
public boolean accept(Stanza packet) {
return true;
}
});
Roster roster = Roster.getInstanceFor(conn2);
//Get all rosters
Collection<RosterEntry> entries = roster.getEntries();
//loop through
for (RosterEntry entry : entries) {
//example: get presence, type, mode, status
Presence entryPresence = roster.getPresence(entry.getUser());
Presence.Type userType = entryPresence.getType();
Presence.Mode mode = entryPresence.getMode();
String status = entryPresence.getStatus();
Log.d("stanza",userType+" "+status);
}
roster.addRosterListener(new RosterListener() {
#Override
public void presenceChanged(Presence presence) {
//Called when the presence of a roster entry is changed
}
#Override
public void entriesUpdated(Collection<String> arg0) {
// Called when a roster entries are updated.
}
#Override
public void entriesDeleted(Collection<String> arg0) {
// Called when a roster entries are removed.
}
#Override
public void entriesAdded(Collection<String> arg0) {
// Called when a roster entries are added.
}
});
conn2.login(mngr.getDeviceId(), "secret");
Presence presence = new Presence(Presence.Type.available);
presence.setStatus("I’m available");
conn2.sendPacket(presence);
ChatManager chatManager = ChatManager.getInstanceFor(conn2);
Chat chat = chatManager.createChat(mngr.getDeviceId(), new ChatMessageListener() {
#Override
public void processMessage(final org.jivesoftware.smack.chat.Chat chat,
final Message message) {
Log.i("MyXMPP_MESSAGE_LISTENER", "Xmpp message received: '"
+ message);
if (message.getType() == Message.Type.chat
&& message.getBody() != null) {
Log.d("stanza", message.toString());
// processMessage(chatMessage);
}
}
});
// Add a packet listener to get messages sent to us
Message message = new Message();
message.setFrom(mngr.getDeviceId());
message.setTo(mngr.getDeviceId());
message.setType(Message.Type.chat);
message.setSubject("jhelloworld");
chat.sendMessage(message);
}catch (Exception e){
Log.d("error",e.getMessage());
}
I took server from here.
server side code.
var startServer = function (done) {
// Sets up the server.
server = new xmpp.C2S.TCPServer({
port: 5222,
domain: 'localhost'
})
server.on('connection', function (client) {
// That's the way you add mods to a given server.
// Allows the developer to register the jid against anything they want
client.on('register', function (opts, cb) {
console.log('REGISTER')
cb(true)
})
// Allows the developer to authenticate users against anything they want.
client.on('authenticate', function (opts, cb) {
console.log('server:', opts.username, opts.password, 'AUTHENTICATING')
if (opts.password === 'secret') {
console.log('server:', opts.username, 'AUTH OK')
cb(null, opts)
} else {
console.log('server:', opts.username, 'AUTH FAIL')
cb(false)
}
})
client.on('online', function () {
console.log('server:', client.jid.local, 'ONLINE')
client.send("")
})
// Stanza handling
client.on('stanza', function (stanza) {
console.log('server:', client.jid.local, 'stanza', stanza.toString())
var from = stanza.attrs.from
stanza.attrs.from = stanza.attrs.to
stanza.attrs.to = from
client.send(stanza)
})
// Stanza handling
client.on('chat', function (stanza) {
console.log('server:', client.jid.local, 'chat', stanza.toString())
client.send(stanza)
});
// On Disconnect event. When a client disconnects
client.on('disconnect', function () {
console.log('server:', client.jid.local, 'DISCONNECT')
})
})
server.on('listening', done)
}
startServer(function (){
console.log("server localhost started at 5222 localport");
});
I tried many solution from stackoverflow and smack community but didnt.
help will be appreciated.

Chat/1:1 Chat in Quickblox Chat sdk

How to get Offline and online user in quickblox private chat between two user.
If two user Jone and kally if kally is offline than how to get status of offline user Kally my code here. Please check and help me.
try {
QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setBody(inputbox.getText().toString());
chatMessage.setProperty("save_to_history", "1");
long time = System.currentTimeMillis()/1000;
chatMessage.setProperty("date_sent", time + "");
privateChat.sendMessage(chatMessage);
showMessage(chatMessage);
inputbox.setText("");
} catch (XMPPException e) {
Log.e("XMPPException",e.toString());
} catch (SmackException.NotConnectedException e) {
Log.e("Not Connected Exception",e.toString());
}catch (NullPointerException e) {
Log.e("NullPointerException", e.toString());
}catch (Exception e) {
Log.e("Exception", e.toString());
}
QBPrivateChatManagerListener privateChatManagerListener = new QBPrivateChatManagerListener() {
#Override
public void chatCreated(final QBPrivateChat privateChat, final boolean createdLocally) {
if(!createdLocally){
privateChat.addMessageListener(privateChatMessageListener);
}
}
};
QBMessageListener<QBPrivateChat> privateChatMessageListener = new QBMessageListener<QBPrivateChat>() {
#Override
public void processMessage(QBPrivateChat privateChat, final QBChatMessage chatMessage) {
Log.w(Tag, "new incoming message: chatMessage" + chatMessage);
showMessage(chatMessage);
playBeepSound(mContext);
}
#Override
public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage){
Log.w(Tag, "new incoming message: originMessage" + originMessage);
}
#Override
public void processMessageDelivered(QBPrivateChat privateChat, String messageID){
Log.w(Tag, "new incoming message:messageID " + messageID);
}
#Override
public void processMessageRead(QBPrivateChat privateChat, String messageID){
Log.w(Tag, "new incoming message:messageID messageID" + messageID);
}
};
private void createNewDialog(){
privateChatManager = QBChatService.getInstance().getPrivateChatManager();
privateChatManager.createDialog(opponentId, new QBEntityCallbackImpl<QBDialog>() {
#Override
public void onSuccess(QBDialog dialog, Bundle args) {
//Log.e("QBdialog", ""+dialog);
//Log.e("id", dialog.getDialogId());
setUpListener();
isQBDialog = true;
}
#Override
public void onError(List<String> errors) {
Log.e("errors", ""+errors);
isQBDialog = false;
}
});
}
private void setUpListener(){
privateChatManager.addPrivateChatManagerListener(privateChatManagerListener);
privateChat = privateChatManager.getChat(opponentId);
if (privateChat == null) {
privateChat = privateChatManager.createChat(opponentId, privateChatMessageListener);
privateChat.addIsTypingListener(privateChatIsTypingListener);
}else{
privateChat.addMessageListener(privateChatMessageListener);
privateChat.addIsTypingListener(privateChatIsTypingListener);
}
}
i am follow link for chat
http://quickblox.com/developers/Android_XMPP_Chat_Sample
I have also tried to implement quickblox chat for one on one chat, which then I got stuck as the documentation is not so sufficient. Then I found out socket.io which is more convenient for one on one chat.follow the link: http://socket.io/blog/native-socket-io-and-android/. You also have to find a free node.js hosting company. I can suggest you the heroku.com
You can add listener for tracking users statuses - RosterListener.
For example:
https://github.com/QuickBlox/q-municate-android/blob/master/Q-municate_core/src/main/java/com/quickblox/q_municate_core/qb/helpers/QBFriendListHelper.java
Q-municate tracks users statuses in real time (private and group chats).

Categories

Resources