Use XMPP to implement a push notification infrastructure - java

I am currently working on a project which requires a server to request data from the devices which are currently connected to the server. Meaning, first the server finds out which devices are connected to the server and then sends an application specific message to the client device which should wake certain functionality present on the client.
I was looking into XMPP service which looked promising since it works as a PUSH notification. The in XMPP can be used to check if the device is currently connected and has subscribed to the server. Since every android user has a gmail account, I was thinking of using the gmail xmpp service to connect /subscribe to the server. Then send specific message to the client, i.e x...#gmail.com.
However if a message is sent this way the client app gets the message as well as the native gtalk client. So how do I go about intercepting this so that it doesn't show up on the gtalk client but my app still gets it ?

Use the full JID when sending the message. The send to multiple clients should only occur when the bare JID is used.
Full JID -> xyz#gmail.com/device
Bare JID -> xyz#gmail.com

Related

How to send a USSD message to a specific user without using any server?

I'm trying to build an android app that would have the basic functionality of sending a short text Message via USSD to a specific mobile number.
is that possible in any way without establishing a web server and only by creating a peer to peer session between two mobile devices?
You can't.
USSD is not IP, web, or whatever technology around internet. USSD works on mobile networks and messages are transported on the signaling network. In other words, whenever you type #xyz# on your mobile phone, as a call or in an app you've developped, the message is sent to your mobile telco operator on a USSD Gateway, a platform hosted by the telco. That gateway may use HTTP(S) to have the request processed and retrieve the menus to be sent back to the user, that HTTP server may be located on the internet, but this is absolutely not mandatory and most of the time it's not the case.
If you want to write a messaging app using USSD, you have to have an agreement with a mobile telco and your app as likely to only work on his network

How to setup a FirebaseCloudMessaging server?

I did the android client side for FCM, I tested it using FCM console.
Now I need to setup a server which gets the registrationId from client using Http link and also sends push notifications. This is the first time I am setting up a server.

Send data to android app from web client

I'm trying to make it such that a click on my web client from a computer can "trigger" the android app to run its set function.
I've searched extensively but it seems like all methods need the mobile device to initiate a connection before the web server can even do anything.
Is there a way for the web client to be the one initiating? Also, is there any way to do this without notifying the user of the device, i.e. in the background? I'm using cakephp for the web client but any kind of answer will be appreciated. Thanks!
Use push notification system to trigger any action on your device. Push notification system such as Parse, PushApps, pubnup etc are available for free and some are paid too. Try them. Send a push notification and listen to that push message and on receiving trigger your action.
Use Google Cloud Messaging .
"Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas."[Google]
Here you'll find how to implement the GCM with PHP.

How does GCM locate a user phone

My question is how does the Google Cloud Messaging know where to send the message to? does it work by IP Address? Is there an interval that runs a function on the phone to send the current location or IP Address of the phone to the Google server? Does anyone know?
Google doesn't need to know the IP address of your device. Instead, your device connects to Google, identifies itself using whatever protocol Google uses for authentication, and Google then uses that established connection to send notifications to your device.
When your phone changes from one IP address to another, it simply makes a new connection to Google, and Google then uses that new connection for your notifications. Google wouldn't even need to keep track of your IP address after you disconnect, since as soon as you disconnect (like on a public wifi system), somebody else might start using that same address.
Here is the link which explains the working of GCM http://developer.android.com/guide/google/gcm/gcm.html
Every GCM client creates a unique device token that you need to send to GCM server for sending the push notifications to client.
Here you can find link explaining the GCM.
GCM Works by Running a Service of its Own to handle Push Notifications.
This service requests the Google Cloud Server (GCM) with your app token ID created by GCM for any pending notifications created by your app and sends the response back with all the notifications from your token id to your app, and this happens for the all the apps using GCM.
So, basically if you have 5 apps which have implemented GCM then their token IDs will be send together by this service and GCM will check if any notification is available for the sent token id's and send them as a response.
Read this thread, this guy has explained it, and GCM is reliable for new app builds !!
http://eladnava.com/google-cloud-messaging-extremely-unreliable/

How to implement XMPP to send push notifications

I would like to use XMPP so that my application will send out updates to an android phone (1.5 and higher). I pretty much want to use XMPP to send push notifications to the phone.
How would i go about achieving this. At the moment my web application is running on apache tomact with a number of servlets so the android phone can access information, but I'm finding it difficult understanding how I could implement XMPP so that I can push information from the server to the client (android phone).
I have tested the below tutorial
Example of XMPP with Google ID login
It uses Google ID logins. But i need to use my webapplication to do what google implements.
Any ideas?
That would depend on the nature of your push (is it a point to point or pub sub). In either case, you will need an XMPP server that your clients and application are connected to. This will be the means for your application to send notifications to the clients.
Not sure what you mean by "I need to use my webapplication to what google implements". Your webapplication would be a client to the xmpp server, just like your phones. You cannot use xmpp to simply talk to your webapplication, unless it happens to be a bosh enabled xmpp server itself, which I would guess is not likely.
You can use Smack for your client communications, and any one of the many available servers.
If the communication is directed at specific clients, then creating a chat between the application and client is probably the simplest means. If it is more of a broadcast, then you could use either MUC (multi user chat) or pubsub.
Generally, you would implement this as a pub-sub feature. Pub-sub is basically the publish/ subscribe paradigm: you publish something and they receive it.
Assuming you have an XMPP server setup that supports the pub-sub protocol extension (like eJabber), in your app, you would login to that server and subscribe to a node (where your update notifications would be sent), and with your subscription you would have to add a handler to handle any notification on that node.
On the server side, when you have something that all of your clients need to know about, you would publish the update to the same node that the clients subscribe to.
For more info, see http://xmpp.org/extensions/xep-0060.html

Categories