I have created an app that send messages between devices using GCM , the thing is
if i want to send several messages in a row its possible that one of the sent messages wont be sent instantly and will be delayed.
My scenario is : I have tried to send 3 messages in a row , i received the first and the third one but couldn't receive the second one !!
One day after I received the second message , how could this be possible ?
Is there any way to sync the sending ? and why it took the second message 24 hours to be received ?
Google is very clear about how you get no guarantee that a message will arrive at all.
In other words, don't depend on messages getting delivered. Your system needs to be robust enough to handle this. Perhaps periodically check. Definitely check if the backend has stored messages you did not receive yet.
If you purely rely on GCM delivering your (chat?) messages, then users will very quickly uninstall your app, because it will be faulty.
Related
We have multiple mobile clients (ios and android) subscribed to a channel-msg.
7 messages are being published to channel-msg by the server:
Messages 1-3 were published to channel.
The device got messages 1-3 via native PubNub.
The user turned the device off.
Messages 4-5 were published to channel.
The user turned the device on, and app in foreground.
Message 6 is published.
Message 6 arrives to the device.
At this point (in the "got PubNub message" callback in the device's code), I don't want to perform Message 6, because I must perform Messages 4-5 first.
I can use the history() API to get the lost messages, but with this strategy I am forced to perform the "history check" on each message I receive on the device, before I can execute it.
I there a better pattern/design to handle this scenario?
PubNub History
You don't need to call history for each individual message, rather, you retrieve all missed messages (up to 100 per history call).
Just save the timetoken of the last received message in a way that you can retrieve it when the app is relaunched (NSUserDefaults). When your app is launched, just use the timetoken as the end param (nil for start param) in your history call.
If you get 100 messages returned (the max) then it is likely you have more and you need to call history again (paging through storage) and again until you receive > 100 messages.
Once you have received the last of the messages, use the timetoken of that last message (the one closest to now), use that timetoken to subscribe to get any message between the last history call and your subscribe and continue to subscribe for further messages.
I've made a small app from where user can send SMS to many users at the same time. I've done it like it is done i all tutorials and it's working fine. I create a SMSManager, divide a message and send it as a multipart:
ArrayList<String> msgArray=smsManager.divideMessage(msg);
smsManager.sendMultipartTextMessage(phoneNo, null, msgArray, null, null);
Everything works fine. The problem is if user wants to send more than 30 messages in a couple of minutes. In that case Android displays a warning:
"{MyAppName} is sending to many messages. Do you want to allow sending messages?"
For each messages above 30 sent messages, I receive that warning. It gives me an option to allow or to deny. The problem is that even if I click 'allow', messages don't get sent.
Imagine a situation where user chooses 35 contacts and want to send a message to all of them. After he clicks send, 30 messages are sent and for other 5 that dialog is displayed where user is asked does he want to allow further sending.
Even if I click 'allow', message doesn't get sent and only 30 messages are sent. This way user gets an impression that all messages are sent but they are not. Those 5 messages are not sent even if he allowed app to send them.
Is there a workaround for this problem? I need some workaround to find out which messages are not sent and the way to send them.
Thank you.
You shouldn't set null on ArrayList sentIntents argument but add actual array of PendingIntent - you can use that to check if your message was sended correctly. Take a look at documentation.
Probably answer to this question also will be helpful.
Hello I am working on a project where GCM is being used very much to notifify users for certain actions. For this sometimes in a 1 minutes server is continous pushing notification (3-4 messages) to same device.
But I noticed that I receive everytime only 1 message then other 2-3 messages are being discarded. I'm not sure if this is intentional to avoid spamming by Google ?
Does anyone have experience of it. Please share.
Thanks in advance.
If you are sending the messages from your server with the same collapse_key, the GCM server will discard some of them if it receives a message with collapse_key X before it managed to send the last message having the same collapse_key.
If you don't use collapse key, GCM server will discard some of your messages if it accumulated over a 100 messages for the same device that haven't been sent yet.
You can read more about it here.
I am using GCM service for my android chat application, sometimes the message sent without any problem and sometimes it fail without any Ack nor Nack..
I don't change any thing, the network is souitable the message is the same as the previuse...
Why does GCM send sometimes and fail sometimes in the same conditions!
point: I send many types of messages other than the chat messages thet the user write directory.
for example I send: ( online status, typing status, profile photo changed...ect)...
these messages sent to my xmpp server via GCM...
does these (many) messages make GCM stop for a while?
I set delay_while_idle = true and TTL=0
sorry for my English I hope you got me!
OK I found that it's common issue in GCM, i.e this is the behavior of GCM.. delay, random thrulling.. I can call this Bug in GCM although the GCM team see that this delays and thrulling are normal and ok ...
So I would like to find alternative...
I found one platforma that not depents to GCM :
http://www.titaniumtutorial.com/2013/10/acs-push-notification-using-gcm.html?m=1
I want to track the number of messages that are sent from an android phone. I'm aware that there is a Broadcast message whenever a SMS is received but there is no particular event for a sent message.
I don't wanna end up counting the number of messages that appear in the "sent" area cos if I delete a sent message, the count will get changed.
Two possible solutions:
You could read the sent messages folder on a schedule, and only count the messages with time stamps that were sent between the last time you checked and the current time you're checking.
You could send the sms yourself (assuming the user is willing to go through your application to do it), then through your pending intent you could easily tell yourself when this was done.
Personally, I like possible solution #1, thought there is the problem that some SMS applications don't even store the sms in the default content provider: content://sms/sent, or like you said, the user might delete the message too quickly before it can even be counted that first time. Unfortunately, I don't think there is a better solution at this time than an hybrid solution of the two solutions I'm proposing, and even that one offers no guarantee that you won't miss some messages.
You can handle this when you send message.
Store the count in the shared preference.
When SMS is sent, increment the value in the shared preference.