I'm trying to send custom IQ from register device to ejabberd xmpp server for FCM configuration but still i can't received FCM notification and receiving Error like "user not registered at XMPP".
Step 1 : Created class for Custom IQ
public class IQGetSomething extends IQ {
public static final String ELEMENT = "push";
public static final String NAMESPACE = "p1:push";
String refreshedToken;
String userName;
public IQGetSomething(String refreshedToken,String userName) {
super(ELEMENT, NAMESPACE);
setType(Type.set);
this.refreshedToken = refreshedToken;
this.userName = userName;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.append("<keepalive max=\"120\"/>" +
"<session duration=\"60\"/>" +
"<body send=\"all\" groupchat=\"true\" from=" + "\"" + userName + "\"/>" +
"<status type=\"xa\">Text Message when in push mode</status>" +
"<offline>true</offline>" +
"<notification>"+
"<type>fcm</type>"+
"<id>" + refreshedToken + "</id>"+
"</notification>"+
"<appid>" + "com.appname"+ "</appid>");
return xml;
}
}
Step 2 : Send stanza to XMPP
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
SmackService.sConnectionState = ConnectionState.CONNECTED;
logI("Before n mostly after login $^&$^$...authenticated ");
logI("authenticated");
if (!mConnection.isSmEnabled()) {
mConnection.setUseStreamManagement(true);
mConnection.setUseStreamManagementResumption(true);
}
if (mConnection.isSmEnabled()) {
logI("stream M is enabled");
} else {
logI("stream M is not enabled");
}
final String refreshedToken = FirebaseInstanceId.getInstance().getToken();
IQGetSomething iqCustomPush = new IQGetSomething(refreshedToken, mUsername);
iqCustomPush.setStanzaId(refreshedToken);
Log.d("xml", iqCustomPush.toXML().toString());
try {
mConnection.sendStanza(iqCustomPush);
} catch (Exception e) {
e.printStackTrace();
}
}
Step 3 : Set Offline
public void setOffline() {
Presence presence = new Presence(Presence.Type.unavailable);
try {
mConnection.sendStanza(presence);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
**LOGCAT
01-18 17:48:29.719 10219-10441/com.appname D/xml:
<iq id='refresh_token' type='set'><push xmlns='p1:push'><keepalive max="120"/><session duration="60"/><body send="all" groupchat="true" from="user_id"/><status type="xa">Text Message when in push mode</status><offline>true</offline><notification><type>fcm</type><id>refresh_token</id></notification><appid>com.appname</appid></push></iq>**
Note :- I changed here my refreshtoken with text "refresh_token" and package name with "com.appname". If anything i'm doing wrong than help me.