在我的应用程序中,当我必须添加朋友时,我通常会发送订阅数据包 4 次
IE
A->B(订阅)
B->A(已订阅)
B-A(订阅)
A->B(已订阅)
每执行一步后,我都会在服务器上看到状态立即发生变化。
但在我的应用程序中,只有在注销并再次登录后才会反映出来。
添加好友后,该人必须注销一次,然后好友列表中才会显示该好友>
有什么问题?我找了很多但没有发现任何错误:(
logcat 中没有显示错误。
我还在发送每个数据包后打印了 syso 输出。它总是显示为“无”(对于向其发送请求的人),并且始终显示为“发件人”(对于发送好友请求的用户)。除非有人登录,否则两者都不会反映出来。退出并再次登录。
请帮我 :(
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;
}
}
它将向其他用户发送通知..允许编写此代码:-
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();
}
});
再次允许发起请求的用户时,会再次执行相同的操作。
请帮忙。订阅状态在服务器上立即发生变化,但在应用程序上,它会在注销一次后更新。
这是代表列表的代码
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