注销在XMPP咂嘴添加好友 [英] Logout to add a friend in xmpp smack

查看:138
本文介绍了注销在XMPP咂嘴添加好友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序时,我有添加好友我平时做派订阅包4次 即

In my application when I have to add a friend I usually do send subscription packets 4 times i.e

A-> B(认购) B-> A(认购) B-A(认购) A-> B(认购)

A->B (subscribe) B->A ( subscribed) B-A( subscribe) A->B ( subscribed)

每一步我在服务器上看到后的状态立即更改。

After each step I see on the server the status changes immediately.

但是,在我的应用程序只涉及到反映注销并再次登录后。 该人已注销ONCE后,他又增加了一个朋友,那么只有朋友是表现在他的好友列表>

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 :(

没有错误显示在logcat中。

No error is showing in the logcat.

我还打印了syso输出后,每一个数据包被发送。它总是说为NONE(在人的情况下,向谁请求被发送),并总是说/从(以谁发送了好友请求的用户的情况下)..两个不反映,直到除非一个人的日志出来,再次登录。

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.

请帮我:(

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;
        }
    }

这将发送通知给其他用户..在允许这种code被写入其中: -

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.

下面是code的重新presents名单

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);
            }           
        }
    }

感谢

推荐答案

有关发送,你必须使用一个请求,

For sending a request you have to use,

roster.createEntry("mail_id", null, null);

和为您在使用监听请求 PacketListener 。并检查 presence

And for Listening the Request you have to listen using PacketListener. And check the Presence

Presence presence = (Presence) packet;
Presence presence_request = new Presence(Presence.Type.subscribed);
presence_request.setTo(presence.getFrom());
presence_request.setType(Presence.Type.subscribed);
presence_request.setFrom("current_logged_in_user");
connection.sendPacket(presence_request);
roster.createEntry(presence.getFrom(), null, null);

这篇关于注销在XMPP咂嘴添加好友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆