Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending alerts / notifications from server side to android application without internet access

I need to send a push notificiation from a webapp to an android app. Basically I just want to inform the android client that new data is available on the server. So it only has to be a string + vibration/sound of the phone.

The (big) problem here is that I am inside a corporate network without access to the internet. This is why I cannot use GCM.

So far I found the following options to accomplish the task without GCM:

  • Use XMPP
  • WebSockets
  • Ajax Polling

Is it possible to include WebSockets or AjaxPolling into a native Android app to trigger events like vibrate?

Is there an easier solution, without that much overhead as with xmpp, since I just need to send a short notification? So far I understand that I need somethink like SMACK XMPP for Android + e.g. Openfire and XMPPHP on the server side for this scenario.

like image 588
AndyB Avatar asked Oct 31 '22 10:10

AndyB


1 Answers

Since nobody replied, I want to provide you with an approach I now try to pursue.

I use Laravel to write the API. It comes with an out-of-the-box support for Redis, which is awesome to Broadcasts Events -> https://laravel.com/docs/5.1/events

The following is just a quick example:

Redis::publish('test', json_encode($data));

Those events are received from a Socket.IO Server-Instance running on the same machine.

var Redis = require('ioredis');
var redis = new Redis();

redis.subscribe('test');

....

server.listen(3000);

Socket.IO has an android client implementation, which allows me to connect to the socket.io server in a native android app. Here is an example: http://socket.io/blog/native-socket-io-and-android/

private Socket mSocket;
{
    try {
        mSocket = IO.socket("http://localhost:3000");
    } catch (URISyntaxException e) {}
}
like image 68
AndyB Avatar answered Nov 15 '22 05:11

AndyB