I want to implement an application where a user receives a notification when some other user has done something. I don't want to user Push Notifications for that, because this information is only relevant, when the application is opened.

I thought of using Server-sent events. According to caniuse EventSource is not supported on Android lower then 4.3.

Does anyone know something about the support of this cool feature in Phonegap / Cordova? Or a plugin which provides this functionality on Android as well? iOS seems to be no problem.

I'm using Cordova 3.1.

Thanks!

有帮助吗?

解决方案

You can have a look at this EventSource polyfill library: https://github.com/Yaffle/EventSource

It's only supported on the Android browser (lower than 4.3 at least) if you add 4k of padding after each message. Perhaps you can also try implementing long polling? It might be a better solution instead of eventsource with 4k padding.

You can read more on this topic here: https://github.com/Yaffle/EventSource/issues/14

其他提示

I solved this issue by using Web-Sockets and a plugin for older Android devices in my Cordova application. The Phonegap WebSocket Plugin provides the same API like the Javascript W3C standard and can therefore be used without any issues on iOS, Android <4.3, and Android 4.3+.

Please note, that we had to use secure Web-Socket connections (wss://) to get it working with 3G connections as mentioned here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top