Hii Guys this is my first time here.
So basically I am trying to send push notifications on Fcm with smack and Openfire pushserver
and I registered and enabled notification on openfire with Smack successfully but when I send a notification openfire log show notification delivered successfully but message received is with null data in fcm android.
This is openfire log
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - Message stored to offline storage. Try to send push notification.
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushServiceManager - User '917015009826' has 1 push notification services configured.
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - For user '917015009826', 1 push service(s) are configured.
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - For user '917015009826', found service 'push.mutthar.com'
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - For user '917015009826', found node 'LoYWMrjmb5hJ' of service 'push.mutthar.com'
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - For user '917015009826', found publish options for node 'LoYWMrjmb5hJ' of service 'push.mutthar.com'
2023.04.09 22:19:56 TRACE [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - For user '917015009826', Routing push notification to 'push.mutthar.com'
2023.04.09 22:19:57 DEBUG [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - Delivered a notification for user '917015009826' to node 'LoYWMrjmb5hJ' on service 'push.mutthar.com'.
2023.04.09 22:19:57 DEBUG [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - Push IQ packet: <iq type="set" id="367-52" to="push.mutthar.com" from="mutthar.com"><pubsub xmlns="http://jabber.org/protocol/pubsub"><publish node="LoYWMrjmb5hJ"><item><notification xmlns="urn:xmpp:push:0"><x xmlns="jabber:x:data" type="form"><field var="FORM_TYPE" type="hidden"><value>urn:xmpp:push:summary</value></field><field var="message-count" type="text-single"><value>1</value></field><field var="last-message-sender" type="text-single"><value>918684923688@mutthar.com/Dakiya</value></field><field var="last-message-body" type="text-single"><value>dysfg</value></field></x></notification></item></publish><publish-options><x xmlns="jabber:x:data" type="submit"><field var="FORM_TYPE"><value>http://jabber.org/protocol/pubsub#publish-options</value></field><field var="secret"><value>voCLuN13SYcpjB5pkVHy5r6i</value></field></x></publish-options></pubsub></iq>
2023.04.09 22:19:57 DEBUG [socket_c2s-thread-3]: org.igniterealtime.openfire.plugins.pushnotification.PushInterceptor - Push message data: <notification xmlns="urn:xmpp:push:0"><x xmlns="jabber:x:data" type="form"><field var="FORM_TYPE" type="hidden"><value>urn:xmpp:push:summary</value></field><field var="message-count" type="text-single"><value>1</value></field><field var="last-message-sender" type="text-single"><value>918684923688@mutthar.com/Dakiya</value></field><field var="last-message-body" type="text-single"><value>dysfg</value></field></x></notification>
2023.04.09 22:19:57 DEBUG [NioProcessor-2]: org.apache.mina.filter.executor.OrderedThreadPoolExecutor - Adding event MESSAGE_SENT to session 11
Queue : [MESSAGE_SENT, ]
and this is how i try to receive message in android
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d("MyFirebaseMessagingService", "Received message data: " + remoteMessage.getData().toString());
if (remoteMessage.getData().containsKey("gcm.notification.x")) {
String notificationData = remoteMessage.getData().get("gcm.notification.x");
// Parse the XML data here
System.out.println("called noti");
}
if (remoteMessage.getData().containsKey("notification")) {
System.out.println("called noti");
String notificationData = remoteMessage.getData().get("notification");
// Parse the XML data here
System.out.println("Notification received: " + notificationData);
}
if (remoteMessage.getData().containsKey("notification")) {
System.out.println("called");;
String notificationXml = remoteMessage.getData().get("notification");
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(new StringReader(notificationXml));
int eventType = parser.getEventType();
String messageCount = null;
String lastMessageSender = null;
String lastMessageBody = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("field")) {
String varValue = parser.getAttributeValue(null, "var");
if (varValue.equals("message-count")) {
eventType = parser.next();
messageCount = parser.getText();
} else if (varValue.equals("last-message-sender")) {
eventType = parser.next();
lastMessageSender = parser.getText();
} else if (varValue.equals("last-message-body")) {
eventType = parser.next();
lastMessageBody = parser.getText();
}
}
eventType = parser.next();
}
if (messageCount != null && lastMessageSender != null && lastMessageBody != null) {
// Do something with the extracted data
}
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
}
}
what I am doing wrong?