I am working on application were i need to send some data to specific user without much of delay.
Actualy I have more then 1000 users who are online out of those I want to select one user and send the data to him only.
I had two solution
1.current implementation=>
So far I am using push notification for this purpose I get the user's device Id and send notification to him but problem is push notification(sending/receiving) depend on my server and GCM
server so it get delayed sometime(I observed sometime it gets delayed by 5 min also).
2.Not implemented=>
Another option is to run thread continuously to check any msg is arrived, if arrived check if whether is meant for same user or not,if he is targeted user then show the data else discard .But here also problem is even if this msg dose not belong to that user one need to check the condition and then discard.
Related
I am using Firebase with OneSignal within an hybrid application (Android + JS with cordova app). In some cases the user may become offline and online while he is still using the application.
Note that you can't retrieve a push notification if you don't have connectivity.
So my question is, is it possible to retrieve a push notification if the another user sends a push notification while the first user is offline, and later on this first user retrieves the connectivity (As a delayed push notification)?
Thanks!
Internally, OneSignal uses Firebase Messaging Service, so the constraints should be looked for there.
Firebase has 2 types of pushes: notification messages and data messages. That matters if you want to show a notification straight when a push comes, or you'd like to do some additional processing beforehand.
Then, you can configure Firebase to store and resend every message up to 28 days. Of course, losing a network connection for some time does not prevent a message to arrive.
There is another limitation though: up to 100 messages can be stored per client. So, if there are more than a hundred, it's better to re-request the diff.
And then, when the device finally comes back to the network, you should decide if you'd like the notification to come immediately even if the app is already minimized or the device is sleeping. Here is a part about push priorities.
Finally, to be able to work with Firebase on this lower level, you may need to configure OneSignal accordingly. Here is an instruction telling how to work with the background notifications, if you need them.
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 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.
In Android, I want to run a service which periodically connects to the server gets the message
and displays the message in full screen to the user irrespective of what the user is doing.
Should I be using the above approach or use GCM to deliver messages to the client device.
What component do I need to use to show a full screen message to the user ?
Notification requires the user to pull down the notification bar and select the notification. I want the message to appear right away in full screen on the user device.
Please let me know what component of android I should use to achieve the above step.
Thanks
A GCM message should do. The additional information needed to show the message can be represented via JSON and parsed by your GCMIntentService. As long as the payload is within 4k the messages will be delivered. The maximum retention time (at the moment) for a GCM message is 4 weeks. You might want to take that into consideration also.
As for displaying the message on the screen, it is possible to register broadcast receivers for an Activity. Alert the broadcast receiver and display the message if the activity is on the foreground.
GCM is used for push notifications. For what you want to do, GCM is not needed at all if you simply want a service running executing some code at your set interval and polling your server. If you want to show a full screen message, simply create an activity and display that each time you execute the code in your interval. Now if you want that message to automatically disappear after a few seconds, then create a custom Toast message.
GCM will simply add another complexity layer that you don't need I think.
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.