如何添加和订阅一个Jabber进入我的XMPP帐户?我的、帐户、Jabber、XMPP

2023-09-07 04:10:44 作者:■ 酒不醉人人自醉

我能增加输入的XMPP账户使用此code。我不能让认购两个,而不是这个我收到

I am able to add Entry to the Xmpp account by using this code. i can't get subscription "both", instead of this i am getting none.

roster.createEntry(abc@xyz.com,ABC,NULL);

如何使用presence 类型添加条目都= ,当我订阅进入此账户。我想知道是否XMPP 发布 - 订阅功能?

How to add entry with the presence type=both, when i am subscribing entry to this account. I want to know whether xmpp publish-subscribe functionality ?

如何获得入境presence通知? 如何发送出站presence通知?

编辑:

public void Addcontact() {    
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
    Roster roster = m_connection.getRoster();

    if(!roster.contains("pa@ace.com")) {        try {           
            roster.createEntry("pa@ace.com", "pa", null);               
        } catch (XMPPException e) {          
            e.printStackTrace();
        }
    }else {
        Log.i("Acc = ", "contains");
    }
}

我加入这样还是我得到presence类型=无帖子。

I am adding entry like this still i am getting Presence Type = none..

推荐答案

下面是我如何添加其他的朋友在我的应用程序。

Here is how i add another friend in my application.

protected void doAddContactToListAsync(String address, String name,
                ContactList list) throws ImException {
            debug(TAG, "add contact to " + list.getName());
            Presence response = new Presence.Type.subscribed);
            response.setTo(address);

            sendPacket(response);

            Roster roster = mConnection.getRoster();
            String[] groups = new String[] { list.getName() };
            if (name == null) {
                name = parseAddressName(address);
            }
            try {
                // final String name = parseAddressName(address);
                // Log.v(tag, msg)

                roster.createEntry(address, name, groups);

                // If contact exists locally, don't create another copy
                Contact contact = makeContact(name, address);
                if (!containsContact(contact))
                    notifyContactListUpdated(list,
                            ContactListListener.LIST_CONTACT_ADDED, contact);
                else
                    debug(TAG, "skip adding existing contact locally " + name);
            } catch (XMPPException e) {
                throw new RuntimeException(e);
            }
        }

只需使用必不可少的部分。

Just use the essential part

Presence response = new Presence.Type.subscribed);
response.setTo(address);
sendPacket(response);

Roster roster = mConnection.getRoster();
roster.createEntry(address, name, groups);

要听传入的请求,注册 addPacketListener 来您的连接

To listen incoming request, register addPacketListener to your connection

    mConnection.addPacketListener(new PacketListener() {

            @Override
            public void processPacket(Packet packet) {

                Presence presence = (Presence) packet;
                    if (presence.getType() == Type.subscribe) {
                    debug(TAG, "sub request from 1" + address);
//Implement accept or reject depend on user action. 
            mContactListManager.getSubscriptionRequestListener()
                            .onSubScriptionRequest(contact);
//or you can test with send back Presence.subscribe first and send Presence.subscribed back to requester.


                } else {// Handle other Presence type.
                    int type = parsePresence(presence);
                    debug(TAG, "sub request from " + type);
                    contact.setPresence(new Presence(type,
                            presence.getStatus(), null, null,
                            Presence.CLIENT_TYPE_DEFAULT));

                }
            }
        }, new PacketTypeFilter(Presence.class));

        mConnection.connect();

按照正确的顺序:

The right order:

在用户1发送订阅用户2。 在用户2发送订阅和Subsribed回用户1。 在用户1发送Subsribed给用户2。

另外一个SO 问题你可以检查

Another SO question you can check

 
精彩推荐
图片推荐