how to use websokets in phonegap application for notify user? - android

I need to write phonegap(ios and android) app that in background listen websockets connection and notify user.
Is any plugin for that, exist? Or any other way to do it ?

I'm pretty sure that the network stack (and therefore WebSocket connectivity) is interrupted when an application goes into the background. I think all you really have time to do is register an APNS / GCM handler when the OS tells you to suspend your application.
You might want to ask this question on the Kaazing Website (there are a few folks there who know this stuff) to confirm this.

This plugin https://github.com/mkuklis/phonegap-websocket adds basic web sockets functionality to phone gap on android. In addition, you can use also socket.io if you want a more elaborate javascript API that what vanilla web sockets provide.

Related

ASP.NET MVC background work - Best practice

I'm developing an ASP.NET MVC 5 application which is supposed to receive and send messages to Android smartphones. The way I have currently implemented it is by using a message broker (RabbitMQ in this case) and let that broker handle the communications between the backend and the smartphones.
In the ASP.NET code I am creating a thread which is run at the beginning of the application in global.asax (I have seen some people who recommends this, maybe I am doing it wrong...). This thread is in charge of listening to the messages that the broker receives and then process them.
My question is: is this a good practice in terms of handling external messages in an ASP.NET application? This is the first time I program this kind of applications and I don't know if I am doing the things right. Does anybody know another ways to receive messages from an external device in ASP.NET? Again, keep in mind I'm very new to ASP.NET, maybe I am asking something stupid but I just need some information about this.
Thanks!
In case someone has a similar question I will answer how I made it work. At the end I used HangFire (http://hangfire.io/), it is quite easy to configure, just need to add this code below in Startup.Auth file:
GlobalConfiguration.Configuration.UseSqlServerStorage("db_name");
app.UseHangfireServer();
app.UseHangfireDashboard();
And the following code to start the background task:
var storage = new SqlServerStorage("db_name");
var client = new BackgroundJobClient(storage);
client.Enqueue(() => rabbitInstance.MethodXYZ());
I hope this solution is helpful for more people.

Syncing offine data with server?

This may be duplicate question but am still having doubt am a beginner in android application i have a couple of doubts my primary doubt is:
I have made one application which will communicate with server when network available it will work as it is. when network is not available data will save in sqlite and later when network is avail need to sync that data to server how can i achieve this.
Whenever there is new update is made with server need to get notification how can i do this
For this one which will be the best approach syncadapter or server or intent service with broadcast receiver which would be opptimized solution for the above requirement
These are all my doubts i would be very glad if someone helps me !!!
If you want an Android app to be notified when something happens on a server you control (without having the app to constantly poll the server to ask for changes), the usual solution is to use Google Cloud Messaging to allow the server to send a notification to the app to tell it to refresh data.
It is kind of complicated to implement, but is the best way to do what you want and is standard practice for mobile apps.
If you need to know when the network becomes available, to reach your server for synchronization, implement connectivity change listener, as discussed in this question.
This does not allow to send messages from the server easily, but if the server messages are not of high urgency, maybe you can simply check for them periodically.
This would allow to use less Google specific infrastructure and change the cloud providers easier.

Create a (phonegap based?) app that listens for incoming HTTP calls

I am looking for options around creating a multi-platform application that will react to a HTTP call made to it. To explain my situation:
I have software running on client machines which is capable of making HTTP requests, specifically passing information via GET;
I can adapt the software to accept a manually inputted IP address and any other information (such as authentication tokens) but not really change the comms method;
The requirement is that this software can pass small amounts of information, on the fly, to an app running on a smartphone;
I'm able to specify networking restrictions, such as being on the same local network etc;
It's not really viable for me to create a server to sit between the app and the client.
My thinking is that I could create a simple app to effectively act as a server, sitting and listening for a HTTP call and acting on the information passed to it.
Phonegap crossed my mind purely for the cross-platform capability; Ultimately, if it needed to be native development, whilst not preferred, it is an option.
Everything I've found on the subject thus far is either specific to a platform, usually with no alternative on competing platforms, or is reliant on the app as a client or an intermediary server handling the connections.
My question is, is such a thing - effectively setting up an iPhone or Android device as a server with a listening port - actually possible in Phonegap, or at all?
I appreciate that there are some (very valid) security concerns with the above approach - additional controls will be put into place to deal with that, right now I'm at the beginning of the search and looking to see which is the most viable way forward.
I would have to say that your approach is a bad idea. You have to keep in mind that the OS can kill your app if it is in the background any time it feels like it. I would look more into using a push service to send the app any updates. That way, even if the app was killed, when the user opens the app it has the latest info. My 2cents.

How to design a remote controller for an android application?

I've written an android application, and I'd like to make it controllable to other machines by sending HTTP request to the device that run my application. I've written a tiny HTTP server and made it start when my application is started. I know I could translate HTTP requests and send messages to various activities to perform UI operations, that need to add listener to all my activities. But in order to make the remote controller code reusable, I hope separate remote controller code from existing application code and thus I need to find a way to make as less as change to the application code to make it be remote controllable.
Could anyone share your ideas?
I dont get what you are asking tbh but in one of application that my friend create, he just implement a mouse pointer which works from any android phone. With that application he can manage to use the android tv.
When he was implementing that app, he took advantage of socket programming and send messages from remote controller, in that situation a phone, to other device and fetch the data in there. In my opinion if you follow such a manner you just dont need to apply so many changes in your other applications. It is all communication in the end.

Long-polling solution in android native app?

i need to build a app to do live reporting, can you suggest a solution that enables real-time communication? I'd like to go with long-polling this approach.
It will be an Android native app, not a web app.
Is there something already written so I do not need to implement it from very beginning.?
I'm a django, python developer.
This is not a polling solution but when I needed something like this I created a foreground service that creates a persistent socket connection to my server. I then registered with some broadcast receivers to maintain my service, on BOOT_COMPLETED and CONNECTIVITY_CHANGE. This worked better for me then C2DM because I had more control of the system and was virtually real time. C2DM is a fire and forget system and is not guaranteed to be reliable. You will have to manage the socket between changes in connections, and maybe hold some kind of wakelock.
For a polling solution, you could also build a web server and poll with http requests. This will avoid the need to manage the socket between connection changes but is not a real time solution.
On the receiving end, there is the Android Cloud to Device Messaging Framework (Google's implementation of push notifications): http://code.google.com/android/c2dm/
Note: this requires Android 2.2 and up (~84% of users as of today)

Categories

Resources