如何向我的 XMPP 帐户添加和订阅 jabber 条目?

2024-03-14

我可以添加Entry使用此代码到 Xmpp 帐户。我无法订阅“两者”,而不是我得到的none.

roster.createEntry("[email protected] /cdn-cgi/l/email-protection", "abc", null);

如何添加存在的条目type=both,当我订阅此帐户的条目时。我想知道xmpp是否publish-subscribe功能?

  1. 如何获取入站状态通知?
  2. 如何发送出站状态通知?

EDIT :

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

    if(!roster.contains("[email protected] /cdn-cgi/l/email-protection")) {        try {           
            roster.createEntry("[email protected] /cdn-cgi/l/email-protection", "pa", null);               
        } catch (XMPPException e) {          
            e.printStackTrace();
        }
    }else {
        Log.i("Acc = ", "contains");
    }
}

我添加这样的条目仍然得到存在类型=无..


以下是我在应用程序中添加另一个朋友的方法。

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 {

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

只需使用必要的部分

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

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

为了监听传入的请求,请注册addPacketListener到你的连接

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

正确的顺序:

  1. 用户1向用户2发送订阅。
  2. User2 将 Subscribe 和 Subsribed 发送回 user1。
  3. 用户 1 向用户 2 发送订阅。

另一个SOquestion https://stackoverflow.com/q/5802607/1050058你可以检查

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何向我的 XMPP 帐户添加和订阅 jabber 条目? 的相关文章

随机推荐