There are several ways to implement a communication application. However, I will make some considerations.
Real time?
No APP is exactly in real time. Who uses Whatsapp, Google Hangouts or Facebook Messenger knows that often the message delays.
What you probably want is something that sends messages as soon as possible.
Simple architecture
Sending the message
Basically you need your App to send the message via an HTTP request. This is simple and just see the documentation.
Example:
final TextView mTextView = (TextView) findViewById(R.id.text);
...
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
Redirecting the message
On the server side, you need a REST application that receives the HTTP request with the message. It would be good for you to lock this into a database for logging and other features.
The technologies used here can be:
- Servlets, JAX-RS or Spring Boot to create web services
- JDBC, JDBC Template or JPA for bank access
Upon receiving the message, your application must, in turn, request an API such as the Google Cloud Messaging to do the push of the message to the devices that are registered to receive it.
An example of a request would be:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
}
Once this is done, Google servers will notify the devices about the message.
To request this API you can use the Apache Http Client library.
Receiving the message
Finally, the messages would be received on the target device(s) in the following method:
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
// Handle received message here.
}
Of course it is necessary that the devices that will receive the messages have the application and that this application register to receive the messages. Example:
private void subscribeTopics(String token) throws IOException {
GcmPubSub pubSub = GcmPubSub.getInstance(this);
for (String topic : TOPICS) {
pubSub.subscribe(token, "/topics/" + topic, null);
}
}
XMPP
This is a protocol that has implementations in Java, but this will not solve most of your problems, such as push to distribute messages to customers.
Behold this link for some implementations you can use on the server side.
However, as I said, you will still have to implement the entire application and message distribution.
Considerations
This is an example at a very high level. I say this is not an easy task.
I suggest you ask specific questions about every point you have questions about and avoid asking so comprehensively about the technology. Probably no one will do all the work and post a step-by-step here.
Hello Jadson. Welcome to Sopt. The question is fair, but I have the impression that it is still a little wide for the site. Have you read [Ask]? I think the chances of you having better answers would increase if you asked the more specific question about some aspect you have doubt about (for example, how to create TCP/IP communication in Java, or how to send a request to an HTTP server, something like).
– Luiz Vieira
Got it @Luizvieira, thanks.
– Jadson de O. Rosa