Is it possible to post data in queue? - android

I've implemented instant messaging through GCM. At the time of sending I show dummy message until app receives acknowledgement.
In this process user can send multiple messages. all through AsyncTask. Sometimes messages are not sending in queue.
My question is:
Is there any method to send messages in queue?

You can take look at these superb queuing library one from Path team and other from Sqaure team
https://github.com/path/android-priority-jobqueue
https://github.com/square/tape
I also heard about "GCM Network Manager" last week in google i/o, check that too.
https://developers.google.com/cloud-messaging/network-manager

Related

Long running service to receive push messages from emqx

I want to implement a long running service to receive push messages from emqx server (even when the program is not running). If I use android Service or JobIntentService, it will be necessary to display a notification which is not intended. If I use WorkManager, The minimum repeat interval that can be defined is 15 minutes. For some reason we do not want to use Firebase. Is there a solution to this issue?
"Push Notification" means "the server triggers your App", so there are two main methods:
use native Android Firebase Messagging create
a persistent connection between all Clients and your Server
First option uses a single connection which is managed by Android for all (or most of) Apps, so the energy compsumption is very low and Connection/Network events are managed by Android itself.
The Second option requires heavy work about Connection/Network re-connections and some work on Server-side. Your server should hold and manage many Client connections for how log it's needed. Moreover the Server should know Client's TCP/UDP handler to know which Client to send message at.
This way drains more battery energy than the first one.
If you intend "Push Notification" as "polling the Server to know if some Notification is ready", then you're misunderstooding "Push" word and you can ONLY create a persistant Service WITH notification icon (this behaviour is mandatory starting from SDK 26).
As you mentioned, in new versions of android, there are many restriction on using background services. Therefore, I suggest you using a hybrid approach if you can. Your server informs the client for new messages using google-fcm service and whenever the client received it, on WorkManager establish a connection to the emqx broker in order to get the actual messages. In this approach you can connect to your broker whenever the app is on the foreground and also you do not send your messages through the fcm but using it as an alarm to clients for new messages.

Android push notification with Google Cloud Messaging and Google App Engine as backend

I want to push notification from GAE backend to Android application. I've successfully implemented communication from this link: https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
But, I'm confused about logic here.
In this example, we have executed client registration to GCM, but via AsyncTask. I want to notify users when some code finishes execution on GAE backend, but without need to call some AsyncTask from Android. All I need is to receive message from GAE when this code finishes it's execution. Is this possible? I just don't know how workflow should be here.
Also, what needs to be done on client side, so that it will "listen" for new messages? Some service task which always runs in background? Or is this already done with public class GcmIntentService extends IntentService from this example, and I just need to identify message type?
If someone could explain this workflow to me, and some code examples would be nice too.
You should really go through the GCM guide, getting GCM running is not hard but it requires a series of steps that cannot be skipped.
In this example, we have executed client registration to GCM, but via AsyncTask. I want to notify users when some code finishes execution on GAE backend, but without need to call some AsyncTask from Android
A complete GCM implementation requires the client to register to GCM servers in order to get its unique ID and YOUR server to store that ID in order to contact that client directly, thats why you need at least one connection to send over this data to your server. you could get around this by using a new feature called topics, that way as soon as the client is registered it could suscribe to a topic and your server wouldn't need to know the specific GCM keys for any of your clients. I wouldn't recommend this last approach as it's not as scalable and will disable any 1 on 1 communication with your server.
Also, what needs to be done on client side, so that it will "listen" for new messages? Some service task which always runs in background? Or is this already done with public class GcmIntentService extends IntentService from this example, and I just need to identify message type?
You need to setup a broadcast reciever to handle incoming messages to your app (all detailed in the guide) from there you get the raw messages and you can do whatever you want with it, includng running it through an intent service as you state or processing it directly on the reciever (not recommended). Yes, you can discriminate message types and execute the logic accordingly.

Periodically send http requests or socket?

I am trying to implement an android IM program,
So far i could send messages from my phone to my webserver and get responses over http but
i am using a timer thread which runs once in 5 seconds for instant messages and an another timer to get friend requests and responses once in 15 seconds. And other timers for other tasks.
It looks fine to me but it requires lots of network connection and uses battery a lot.
I woud like to ask if there is a better solution.
Thanks in advance.
Instead of polling for messages you can use push notifications to tell your app when it should check for new messages.
http://tokudu.com/2010/how-to-implement-push-notifications-for-android/
You could also just use one connection and xmpp. The smack library has been used to implement chat. Take a look here.
Android and XMPP: Currently available solutions

how to write a tigger in sql server to send a push notification (GCM) to android phone?

i have applied the demo code of GCM for server side on appache server and for client side on android device and it is working great; but i need to activate this service in my application as follows:
i have a database on SqlServer and need to automatically send a push notification to android phone whenever some certain data gets modified, i think i should use an after update and after insert trigger to do this, but i don't know how to do it.
any help will be appreciated, thanks in advance.
You should not do it from a trigger. Adding the latency of a GCM push to each table update will quickly bring the performance to unbearable lows. You have to decouple the trigger from the GCM call, and the best way to achieve it is via a queue.
You can use a table as a queue and have an external process monitor the queue and handle the GCM call.
You can use Service Broker and deliver the GCM call from an internal activated procedure or from an external process that monitors the queue
You can use MSMQ and monitor an NT queue from an external process.
My recommendation would be to go with first option as is the simplest and has the inherent robustness of simplicity. Read the linked article to understand what is required to use tables as queues, and do not cut corners.
All options still rely on a trigger to enqueue the notification, but it will be a local enqueue, not a GCM call.
I'm sure someone will think of the naive solution of invoking GCM from the trigger itself using SQLCLR: don't do it.

Android IntentService SMS Queue Handing

I'm writing an Android App that receives text messages from a server via HTTP. I have a button on my App labeled "Poll". When I press this button, the App Polls the a server via HTTP and fetches some text messages.
These texts messages are to be sent out via SMS. What I would like to happen, is for there to be a background queue where these messages are added to. As soon as a message is added to the queue, the queue must immediately be attempted to be "flushed" (i.e. send all pending SMSs over the network). If the sending fails, the App must retry by itself every 60 seconds indefinitely.
What is the best way to achieve this? I guess I'm looking for some form of implementation where an IntentService has a timer that expires every 60 seconds, but can be forced to be expired on demand once a new text message comes in.
I'm ok regarding SMS functionality, as I've been following this guide: http://mobiforge.com/developing/story/sms-messaging-android
It's just the queue handing I need some help with.
Any help is appreciated, thanks

Categories

Resources