In my application when I have to add a friend I usually do send subscription packets 4 times i.e
A->B (subscribe) B->A ( subscribed) B-A( subscribe) A->B ( subscribed)
After each step I see on the server the status changes immediately.
But in my application it only comes to reflect after LOGGING OUT and LOGGING in again. THE PERSON HAS TO LOGOUT ONCE AFTER HE HAS ADDED A FRIEND AND THEN ONLY THE FRIEND IS SHOWN IN HIS FRIEND LIST>
What's the problem? I have found a lot but didnot found any error :(
No error is showing in the logcat.
I have also printed the syso output after each packet is sent. It always says as NONE ( in the case of the person to whom request is sent ) and Always says TO/FROM ( in the case of the user who has sent the friend request ).. Both is not reflected untill and unless a person logs out and logs in again.
Please help me :(
Add Friend Function
public boolean addFriend(String jid) {
String nickname = null;
String idExtension = jid+"@abc.hostname.com";
nickname = StringUtils.parseBareAddress(jid);
if (!roster.contains(idExtension)) {
try {
roster.createEntry(idExtension, nickname, null);
//to subscribe the user in the entry
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(idExtension);
connection.sendPacket(subscribe);
return true;
} catch (XMPPException e) {
System.err.println("Error in adding friend");
return false;
}
} else {
return false;
}
}
It will send a notification to the other user.. on allowing which this code is written :-
btn_Allow = (Button)findViewById(R.id.btn_manageNotification_ALLOW);
btn_Allow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//accept the friends subscription
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo(id);
connection.sendPacket(subscribed);
mCustomProgressDialog = CustomProgressDialog.createDialog(
ManageNotification.this, "", "");
mCustomProgressDialog.show();
mCustomProgressDialog.setCancelable(false);
new Thread(){
public void run() {
try {
sleep(5000);
//mXmconn.getContactList();
/*Presence subscribed = new Presence(Presence.Type.subscribe);
subscribed.setTo(id);
System.out.println("The user is :"+id);
connection.sendPacket(subscribed);*/
} catch (InterruptedException e) {}
mReturnUserMenu.sendEmptyMessage(0);
};
}.start();
}
});
same it is done again on allow again to the user who initiated the request.
Please help. The subscription status is changing on the server instantly but on app it is updating after logout once.
Here is the code which represents the lists
public void getContactList(){
roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
System.out.println("Total=="+entries.size());
mfriendList.clear();
mfriendPendingList.clear();
mfriendRequestList.clear();
for (RosterEntry entry : entries) {
mFriendsDataClass = new FriendsDataClass();
mFriendsDataClass.friendName = entry.getUser().toString();
String user = entry.getUser();
int index_of_Alpha = user.indexOf("@");
/*System.out.println("The current working user is : "+user);
System.out.println("His status is"+entry.getType().toString());*/
String subID = user.substring(0, index_of_Alpha);
Presence availability = roster.getPresence(user);
Mode userMode = availability.getMode();
mFriendsDataClass.availability = "";
mFriendsDataClass.friendNickName = subID;
mFriendsDataClass.friendStatus = stusMsg.toString();
mFriendsDataClass.friendState = retrieveState_mode(availability.getMode(),availability.isAvailable());
if(entry.getType().toString().equalsIgnoreCase("to")){
//getContactList();
mfriendRequestList.add(mFriendsDataClass);
}else if(entry.getType().toString().equalsIgnoreCase("from")){
//getContactList();
mfriendPendingList.add(mFriendsDataClass);
}else if(entry.getType().toString().equalsIgnoreCase("both")){
//getContactList();
mfriendList.add(mFriendsDataClass);
}
}
}
Thanks