AnsweredAssumed Answered

How to send custom XMPP IQ for FCM with ejabbered configuration

Question asked by vishal patoliya on Jan 17, 2017

I want to send this IQ when connection will authenticated.

 

 

<iq type='set' id='123'>

<push xmlns='p1:push'>

<keepalive max="30"/>

<session duration="60"/>

<body send="all" groupchat="true" from="jid"/>

<status type="xa">Text Message when in push mode</status>

<offline>false</offline>

<notification>

<type>applepush</type>

<id>DeviceToken</id>

</notification>

<appid>application1</appid>

</push>

</iq>

 

 

 

and i tried this

 

 

        String childElementNameTicket = "push";

        String childElementNamespaceTicket = "p1:push";

 

 

        final String refreshedToken = FirebaseInstanceId.getInstance().getToken();

 

 

        IQ iq = new IQ(childElementNameTicket, childElementNamespaceTicket) {

            @Override

            protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {

                //xml.append("<iq type='set' id=" + "'" + refreshedToken + "'" + ">");

                //xml.append("<push xmlns='p1:push'><keepalive max=\"30\"/>");

                xml.append("<keepalive max=\"30\"/>");

                xml.append("<session duration=\"60\"/>");

                xml.append("<body send=\"all\" groupchat=\"true\" from=" + "\"" + mUsername + "\"/>");

                xml.append("<status type=\"xa\">Text Message when in push mode</status>");

                xml.append("<offline>true</offline>");

                xml.append("<notification><type>fcm</type><id>"+ refreshedToken + "</id></notification>");

                xml.append("<appid>com.azova</appid>");

                //xml.append("</push>");

                //xml.append("</iq>");

                return xml;

            }

        };

 

 

        iq.setType(IQ.Type.set);

        iq.setStanzaId(refreshedToken);

 

 

        try {

            mConnection.sendPacket(iq);

        } catch (SmackException.NotConnectedException e) {

            e.printStackTrace();

        }

Outcomes