Reputation: 40198
Is it possible to receive notification on mobile devices whenever it's generated from the web Server.
This thing can be achieved by native apps for iPhone and Android. But my requirement is to achieve the same via a mobile website. Also is it possible to receive notification even if the user has closed the web browser.
Upvotes: 6
Views: 4032
Reputation: 56
You can also use Server Sent Events (SSE) for this purpose. Android ICS supports SSE, if I am not wrong. HTML5 rocks (http://www.html5rocks.com/en/tutorials/eventsource/basics/) has an article on this and also point to a demo (http://googlecodesamples.com/html5/sse/sse.html).
However, none of these solutions (websockets, SSE) would be useful if you want your app to work in older Android devices as well. These solutions are not useful if you want to receive push when your app is not launched. The best solution is to build some sort of a hybrid app as suggested by richbayliss. I guess you do not really need phonegap for this. You can fire an event using loadDataWithBaseURL of WebView
Upvotes: 0
Reputation: 723
It is not possible to recieve notifications once the page in the browser ist closed. Notifications are triggered by apps running in the background of the smartphone os.
Upvotes: 1
Reputation: 620
It is possible to acheive, and you have 2 main ways to achieve this:
Both methods require some trick server software, a good example is Socket.IO running on Node.JS platform.
Websockets require an HTML 5 browser (eg, Chrome) so might not work for your requirements.
HTTP long polling is the act of accepting an inbound HTTP connection on the server, and then sleeping until you wish to push the data to the client. Node.JS can be set to do this quite easily, or you could use Socket.IO (a library on Node.JS) which provides extra functionality. Socket.IO also works with Websockets where possible - and falls back to long polling if it has to.
In short, you will need a server platform to do this - I suggest you look at Socket.IO to start with. You can always roll your own once you have the main concept nailed. I wrote one in ASP.net which worked quite well, for example.
Upvotes: 2