Android | Push notifications on local network - android

I've been doing a lot of research without success on finding a solution to my (simple) problem. I'm building an application that does not requires to be connected to the internet but it does consumes a restful API from a server installed in the local network LAN.
Currently I'm dispatching a HTTP request every minute to see if there were any changes in the DB and alert the user of said changes. However this is not very efficient and it results in a poor performance / battery drain.
I've heard that push notifications can be implemented using Google cloud messaging, but that is not an option since it requires to go through google servers, in other words, internet.
I'm using Square's Retrofit framework for handling HTTP requests on Android, and PHP + Laravel on the server side.
Is there a way to send push notifications? If not, is 'long polling' a good practice in Android? Will it even work with Retrofit?

On server side you can use an XMPP server, there are some XMPP servers such as Openfire, ejabberd and SleekXMPP. Please have a look at them.
On Android side you can use a client library e.g Smack or Xabber, the mobile library will automatically update with notifications or events using listeners.
I hope this helps.

I have no idea hot it works, but have you looked into specific packages like this one?
https://github.com/davibennun/laravel-push-notification

Related

Firebase XMPP Protocol Vs HTTP Protocol

Currently I am planning to use Firebase Cloud Messaging with my Android and IOS APP.
In Firebase there are two type of protocol HTTP and XMPP, so my question is when to use which protocol. In which scenario which protocol performs the best.
Thank you all in advance.
From what source you have got that Firebase does not work in emulator!! I am developing an app using genymotion emulator and it works good. Also about HTTP and XMPP what protocol you use depending on the server you will be using. HTTP is simple to use and a lot of people go with it while XMPP is complicated to implement on the device and server as well.
But XMPP may be harder it supports downstream and upstream messages means you can also send a message from a device to your server. But XMPP is good as it does not take a lot of charge and battery.
But nearly everyone use HTTP. And implement upstream messages by your own implementation!!
IMO this does not matter a lot pick the one which u feel more comfortable with.
Only thing I can state is that XMPP is protocol created for communication so if your notifications consist of short frequent messages pick this one, otherwise pick HTTP, which is more commonly used
Sincerely I have experience just with HTTP and it works really well
According to my view, use HTPP. because XMPP requires HTTP more than HTPP requires XMPP.
XMPP is an open standard technology protocol used to presence indicator and instant messaging, while for HTTP had good features and the same time it works better than XMPP.

Sending data from ASP.NET to android

I'm creating a viber-like application, i.e. android users can make instant messages in their android-powered devices. I've created client-to-server webservices using ASP.NET (ASMX service with JSON response) and it works like a charm, but the other side, i.e. server-to-client requests is just a little headache. Of course I can make my application so that there is no need to server-to-cliend requests (sending dummy requests from client to server in short periods) but in this way server will be overloaded specially when number of users increases. I've found some technologies regarding instant messaging, including GCM and XMPP. What are my other options? or let me ask what is my best option?
Should I use sockets? If so, how can I always have my clients IP (considering that clients are mobile users which may be using WiFi or GPRS/3G/4G internet). I'm thinking of a system in which my clients send their IP each n seconds (n can be around 30), so server always has a (nearly) up-to-date list of client IPs.
Is it possible or even logical to do so?
You should definitely consider using GCM (Google Cloud Messaging for Android)
You need to setup a few things in your server to be able to use it to send via GCM.
Its the built-in way to send data from a server to an android device, hope this can help
Implementing GCM Server
Using the good old strategy of long-polling is always possible, but there are much better ways to do it nowadays. That's perhaps the fastest to implement of the mentioned (not so if you want to implement it correctly and with min amount of load on your server/DB engine). I've seen some projects that start around that architecture with the idea to move to something better in the future .... and the moment to move never comes of course. If you start browsing your Android phone connected to a proxy like Charles you'll see what I mean :)
WebSockets are an option, but I don't see a reason why I'd use them for a Viber-like app, which is event-based (you've received a message) and not "real-time" (monitoring some stock graphics movements for example).
Your best choice here is a Google Cloud Messaging (GCM)! It's easy to implement it both on your backend and on the client, and it's built specifically with the problematic connectivity in mind (switching between wifi/poor 3g/4g/etc). It has some pretty nice features that other methods don't provide "out of the box" - message resending (the common scenario of a client loosing his connection - GCM it'll send the push notification later, when he comes online), automatic syncing between devices (smartphone, tablet, etc) and others.

Android react to DB changes

I'm building an Android application that consumes a RESTful API.
When I make a http request to the server I get a JSON response that I can then parse and display appropriately on the screen. So far so good.
Now as my application is going to have multiple users I'd like to refresh this information to all users when any of them changes it.
I know that you can accomplish something similar using AngularJS but I'm not sure you can use that on Android.
My only other idea is to make http requests from the mobile app every X period of time, say 30 seconds (but this is not very elegant and would consume lots of network resources).
Any ideas of how to solve this? Thanks!
PD: I used Laravel to build my REST API.
Either you will use a background thread to check your server for changes every once in a while(basically polling from server), or you use push notifications (whenever something changes on your server side, server will push the data that changed to you). Preferably push should be the way you choose cause it is both user and battery friendly. Also eases your server load.
In android, push notifications implemented mostly by using GCM. You can read rest through here http://developer.android.com/google/gcm/index.html
For a local network, you can use MQTT. There is an excellent blog post about it here http://dalelane.co.uk/blog/?p=1599 .

Is there a way to implement GCM (or CCS) with a server using c++?

I'm working on an App that I've made for both iOS and Android. On the iOS side, I use a constant TCP connection and JSON messages for the push notifications. I want to do the same thing for the android version, however I'm not sure if it's possible. I think using the Cloud Connection Server http://developer.android.com/google/gcm/ccs.html is the way to go, however it only shows samples for Java and Python. Is it possible to use this in c++?
You can choose whatever programming language to desire to implement the server side. The question is whether you can find an easy to use XMPP C++ library for connecting to the Cloud Connection Server.
I assume it will be easier to find an HTTP C++ library for sending HTTP requests to the GCM HTTP Connection Server. If you are not planning to use the upstream functionality (device to cloud), you don't need to go though the trouble of implementing/using the XMPP protocol.

Any messaging framework for server-client communication in android?

I have go through several posts in the internet but did not get a straight and clear answer for this.
I am doing one app on android which needs data to be sent/received from a database over internet. So how I can send/receive messages from my remote database on my android device?
Is there any messaging framework available currently in the android to do this type of task?
One method I thought of is to have PHP scripts at my web server and I will call those php scripts from my android httpClient. But its a bit tire some and error checking also a bit problem and retry mechanism also not there.
Please suggest a good way.
Google have a service for that.
Google Cloud Messaging for Android
Google Cloud Messaging may be suitable just for sending push notifications to android devices and things like that. And XMPP could be used to send messages from one android to another. So what you have taken, using a PHP script and calling it using a URLConnection or HTTPConnection is a better way to make transaction with a remote database

Categories

Resources