Search code examples
androidpush-notificationxmppopenfiresmack

Push notifications in android without using GCM


I've always used GCM for push notifications in android apps, but for security constraint i'm obliged to avoid GCM and use local push server, i've found a lot of answers for this question but none of them is well structured, i hope to get a clear answer for step by step process to use some XMPP server and client libraries for this topic


Solution

  • You may not fully understand what is GCM and what GCM was designed for.

    Traditionally, each desktop applications establish its own TCP connection to its own server, just like you can connect to your Openfire instance and send/receive messages when you want without any third-party services.

    This approach have many issues in mobile environment:

    1. mobile devices are resource limited: when you have many TCP connections open it will drain your battery fast
    2. mobile devices are not have persistent network connection: you should care about cellular and/or wifi network changes (and it also have battery impact) and you should not lose any messages in these unstable environment.

    To solve these problems, Apple, Google (and also their minor competitors) provide "notification services". They are consists of:

    1. System-wide background application ("service") which keeps connection to Apple/Google "notifications" infrastructure servers.
    2. API for developers, to "register" their applications both on server and client side: your server-side application send all events to Apple/Google, and you client app receive "pushes" from that system service, you no need to care about network outages and battery impacts - all issues are handled by OS manufacturer.

    But when you are trying to "avoid GCM" you getting all things to be cared by you, plus:

    1. Your "handmade" persistent network service will interfere with Google's one, and will at least double network and battery usage (or even more, just because your implementation will have errors/other corner cases which are already where solved by Apple/Google big engineering teams)

    2. Your application will dramatically more complex, and you will have much more security issues (as security issues are now handled by you, too) and poor user experience (applications with "own" networking are often have bad UX design, prompting and boring end user with network error messages, for example).

    So, to sum up:

    1. Yes, technically, you can take smack library and connect to Openfire server. Basically it the same as GCM works.
    2. No, in 99.9999% of cases you should not go this way. Unless you are a big company which develops competing mobile platform.