Smack Push Notification not working - android

I am using Smack library to get XMPP pubsub requests in my Android App.
I want to send alert from 1 phone which is received on another phone as push notification popup.
On debugging, control returns null due to this code in Smack 4.2.0 library's ChatManager.java class.
EntityJid userJID = from.asEntityJidIfPossible();
if (userJID == null) {
LOGGER.warning("Message from JID without localpart: '" + message.toXML() + "'");
return null;
}
My from isnt null,ofc... but, my asEntityjidIfPossibe is null.
My Iq is as follows:
<iq
to="pubsub.foo"
from="notifier#foo"
type="set"
id="1523272621323">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish xmlns="http://jabber.org/protocol/pubsub"
node="/home/foo/notifier/c7215880-a36e-4cb9-bdd3-441cf9c29c31/pqr">
<item id="item11523272621323">
<json xmlns="urn:xmpp:json:0">
{"id":"b7da305d-77c2-422a-9c95-7ec8a347192e",
"orgId":"c7215880-a36e-4cb9-bdd3-441cf9c29c31",
"user_id":"f0622ed6-860f-4f4e-9b11-c4ab6cb8cd66",
"username":"xyz",
"subject":"Message",
"body":"hello all",
"priority":"NORMAL",
"ack_required":false,
"users":["pqr"],
"replyTo":["/home/foo/notifier/c7215880-a36e-4cb9-bdd3-441cf9c29c31/xyz",
"/home/foo/notifier"]}
</json>
</item>
</publish>
</pubsub>
</iq>
All I want is to see if message sent is recieved or not? And how to get data to process it...Data is sent perfectly on the server from the sending phone.
On recieving device,
I get this message TWICE,
Message from JID without localpart: '<message to='xyz#foo/5301412210663914056363834' from='pubsub.foo'><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='/home/foo/notifier/c7215880-a36e-4cb9-bdd3-441cf9c29c31/xyz'><retract id='item11523351450156'/></items></event></message>'

Related

Why is message struct always empty in my C++ implementation of Listener

I'm working on FCM in a Qt app for Android and iOS. I've implemented a ::firebase::messaging::Listener in C++ which should pick up the messages and feed the information through to the QML layer for display etc.
Using sample code, the Listener implementation is registering fine, and the Listener::OnTokenReceived implementation is getting a token which I can then send back to my server to use as a registrationid when sending messages.
The problem is that every time I send a message through FCM, either using the on-line message composer or using a curl request, the message structure that is received by the OnMessage implementation has no content.
Here is the implementation (note that m_handler is a singleton component that connects to the QML layer: setNote() stores the QString and emits a signal.)
void FBListener::OnMessage(const ::firebase::messaging::Message & message)
{
QString msg;
::firebase::messaging::Notification * n = message.notification;
if (n)
{
msg.append(n->title.c_str()).append("\n");
msg.append(n->body.c_str()).append("\n");
}
else if (!message.data.empty())
{
for (const auto& field : message.data)
{
msg.append(field.first.c_str()).append(": ").append(field.second.c_str()).append("\n");
}
}
m_handler->setNote(msg);
}
Here is a snapshot of the QtCreator debugging pane if a breakpoint is set on the first line of the above method and a message is sent through FCM.
and here is an example of the message I'm sending through a curl request (in my case I have a PHP script doing this as part of the server backend) The message is being sent successfully.
{
"registration_ids":[
"dAabVuI7Yuo:APA91bFEKguIMhJi0InKhfby-uDLgnhM9__-b9AxOKMguMtoNQsGU3I3ro_9VROYNyr90o9yhC9YseyIwh33pSA6ZpssBgEh1XOFRAHPYaCO5rAvVPVss9rvL5T0ADqafsB0VNahAOwv"
],
"notification":{
"body":"This is a test message",
"title":"test message",
"icon":"notify"
},
"data":{
"test":"This is a test",
"number":1
}
}

update single row item in listview android

i am developing android chat application like whatsapp/hangout.
what i am doing is, Once message is sent to server, the status for message is "sent". And when i receive acknowledgement for that message, i want to change the status for that message to "Delivered".
How to do that ??
Code before sending to server
ChatMessageModel chatMessageModel = new ChatMessageModel();
chatMessageModel.setId(nextId);
chatMessageModel.set_id(null);
chatMessageModel.setGroupId(groupID);
chatMessageModel.setMessage(message);
chatMessageModel.setSenderUserId(user.getUserId());
chatMessageModel.setSenderDisplayName("");
chatMessageModel.setDateSent(null);
chatMessageModel.setMessageType("message");
chatMessageModel.setStatus("sent");
chatMessageService.saveIndMessage(chatMessageModel);
mChatMessageCustomAdapter.add(chatMessageModel);
mChatMessageCustomAdapter.notifyDataSetChanged();
After receiving ACK from server, code is
chatMessageModel.set_id(msg.getString("_id"));
chatMessageModel.setGroupId(msg.getString("groupId"));
chatMessageModel.setMessage(msg.getString("message"));
chatMessageModel.setSenderUserId(msg.getString("senderUserId"));
chatMessageModel.setSenderDisplayName(msg.getString("senderDisplayName"));
chatMessageModel.setStatus("Delivered");
****here how do i update status to "delivered"***
Use update method instead of add inside your adapter and update at particular position and then use notifyitemchanged().

Parse Push is not working with Parse Sever

I am a newbie on parse server and have been using it with my android app. But I am having trouble with implementing push notifications. I do not know how to get logs so any guidance will be much appreciated! The installation class does not contain any "GCMSenderId" or "deviceToken".
Here is how I set up parse server to implement push notifications.
Parse Sever : 2.2.7
1) Developer Console
a) I create a new project using the new console and clicked on the overflow menu --> Project Info and got my project number.
b) Then I went to the "Credentials" page and clicked on Create Credentials --> Api Key --> Server Key and left everything default and clicked create.
c) I got the key for my project. Let it be "MY_API_KEY".
2) Now I setup my parse server app to use this api key and project number as you can see from the image.
enter image description here
3) Now I setup my android app manifest accordingly as you can see from the picture below.
enter image description here
I also added ParseInstallation.getCurrentInstallation.saveInBackground();in my app's Application class.
I am trying to send notifications using the parse dashboard
Please provide any help if possible, thanks!
to send push notification from parse server you have to implement cloud code
in Javascript or another programming language.
below is some code in JS to send push notification to a user
function(objectids,msg) {
var pushQuery = new Parse.Query(Parse.Installation);
msg.default="default";
pushQuery.exists("deviceToken");
pushQuery.containedIn('userObjectId',objectids);
try
{
Parse.Push.send({
where: pushQuery,
data: {
alert:msg.msgInfo,
str:msg,
sound:msg.default
}
}).then(function() {
console.log("push successfully sent");
}, function(error) {
console.log("error while send pn:"+error.code+":"+error.message);
throw "Push Error " + error.code + " : " + error.message;
});
}catch(error)
{
console.log("error while send pn:"+error.code+":"+error.message);
}
}

Python gcm and Django : response is always empty

I am using python gcm for Django.response=json.dumps(gcm.json_request(registration_ids=reg_ids,data=data)).response is always NULL. But message is sent
Their documentation suggested:
response=json.dumps(gcm.json_request(registration_ids=reg_ids,data=data))
Well! Message is received to mobile successfully. But the problem is response value is always empty.
My code:
def sendNotification(request):
gcm = GCM('AIzXXXXXXXXXXXXXXXXXXX')
reg_ids=[]
devices=Devices.objects.all()
for device in devices:
reg_ids.append(device.gcm_reg_id)
data = {'sender': "someone",'message':"Cool!",}
response=json.dumps(gcm.json_request(registration_ids=reg_ids,data=data))
return HttpResponse(response)

Message id issue connecting chat between iOS and Android in Quickblox

I'm having an issue connecting an iOS and Android device with their corresponding QBChat libraries, with the message ID's.
Message objects in Quickblox's iOS library are defined as QBChatMessage objects, that doesn't exist in Quickblox's Android library (which delegates them to a Message class in SMACK library).
The problem is that QBChatMessage class manages message id's as integers, while Message class manages them as Strings. Every message sent from my Android device has a 7-character unique string + a number with the message's position in SMACK chat. When my iPhone receives the message, its ID is a number with the ID from SMACK parsed as much as it could, as in this communication sample (taken from the Android device):
SENT <message id="D64u5-4" to="102521-1799#chat.quickblox.com" from="132505-1799#chat.quickblox.com/Smack" type="chat"><body>{"content":{"text":"hello"},"type":1}</body><thread>7J9230</thread></message>
SENT <message id="D64u5-5" to="102521-1799#chat.quickblox.com" from="132505-1799#chat.quickblox.com/Smack" type="chat"><body>{"content":{"text":"yeah"},"type":1}</body><thread>7J9230</thread></message>
SENT <message id="D64u5-6" to="102521-1799#chat.quickblox.com" from="132505-1799#chat.quickblox.com/Smack" type="chat"><body>{"content":{"text":"test"},"type":1}</body><thread>7J9230</thread></message>
RCV <message id="0" from="102521-1799#chat.quickblox.com" type="chat" xmlns="jabber:client" to="132505-1799#chat.quickblox.com"><body>{"content":{"text":"hello"},"type":1}</body></message>
RCV <message id="1" from="102521-1799#chat.quickblox.com" type="chat" xmlns="jabber:client" to="132505-1799#chat.quickblox.com"><body>{"content":{"text":"yeah?"},"type":1}</body></message>
RCV <message id="2" from="102521-1799#chat.quickblox.com" type="chat" xmlns="jabber:client" to="132505-1799#chat.quickblox.com"><body>{"content":{"text":"yeah!"},"type":1}</body></message>
Message's ID is important for me, in order of database storage. How is this possible? What should I do to solve this issue?
Thanks, kind regards! :)
Daniel, sounds good.
Is changing type of QBChatMessages.ID to NSString will solve your issue?
Will do that in next release. If you haven't time to wait - just write with your request to assist#quickblox.com, will make special build of SDK for you
Below is my Android code for group chat:
/* Sends messages */
public void sendChatMessage(String text)
{
Message message = muc.createMessage();
message.setBody(text);
message.setPacketID("ABC_1");
muc.sendMessage(message);
}
/* Listens for messages */
public void receiveMessage()
{
muc.addMessageListener(new PacketListener() {
public void processPacket(Packet packet)
{
final Message message = (Message) packet;
log.i("packed id: ", packet.getPacketID());
log.i("message id: ", message.getPacketID());
}
});
}
The output I see in logcat is
packet id: null
message id: null
Could you please tell me why the IDs are null? Am I missing something here?

Categories

Resources