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

前端之家收集整理的这篇文章主要介绍了android – 如何添加和订阅jabber条目到我的XMPP帐户?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以使用此代码将条目添加到Xmpp帐户.我无法订阅“两者”,而不是我没有得到.

roster.createEntry(“abc@xyz.com”,“abc”,null);

当我订阅此帐户的条目时,如何添加在场类型=两者的条目.我想知道xmpp是否发布 – 订阅功能

>如何获取入站在线通知
>如何发送出站在线通知

编辑:

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 Type = none ..

解决方法

这是我如何在我的应用程序中添加另一个朋友.
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);
            }
        }

只需使用必要部分

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

Roster roster = mConnection.getRoster();
roster.createEntry(address,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,Presence.CLIENT_TYPE_DEFAULT));

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

        mConnection.connect();

正确的顺序:

> User1发送订阅给user2.
> User2将Subscribe and Subsribed发送回user1.
> User1发送Subribed到user2.

你可以检查另一个SO question

猜你在找的Android相关文章