Chat application android guidance - android

I'm trying to create a chat application and I need a little bit of guidance. I have a login system in place which is working. The user logs in/registers and everything is stored in a mysql database on the server.I know how to handle post requests and send stuff back.I have a recyclerView that can display the messages, but my problem is as follows:
Let's say I have 2 android devices: Android1 and Android2. Android1 sends a message to Android2. The message gets stored to the server. How do I tell the server to direct that message to Android2, and how do I make Android2 receive the message.
What if Android2 was offline at that time.Do I create some sort of response from the phone to tell the server that the message wasn t delivered so it can be sent again? And now how do I program the server to send the message again?
The messages table should be something like- senderId, receiverId, message; or what's the best way of designing it?
I found out about that I can do it either by using GCM, PHP and MYSQL from here http://www.androidhive.info/2016/02/android-push-notifications-using-gcm-php-mysql-realtime-chat-app-part-1/ and also that I can use XMPP. Which approach is best? I prefer the first one because I understand it and it's easy to implement. I have no idea what's happening with XMPP. I created a windows server using firebase, but can I still use my php one somehow ? And also the connection confuses me. I have facebook login implemented. Are there any good tutorials on the xmpp+android out there. I found some, but they are unclear.
Edit: Why is this question getting down votes? What's so wrong with it?

I had to face exactly the same situation as this sometime ago. What I have found in my researches was:
Use Telegram API: telegram is a well consolidate open source app for chat messages, it handles all aspects of it, including security and all the UI stuff. Its license, although, oblies you to make your code open as well;
Use Google Cloud Message Service: GCM allows you to send push to many devices using either REST or XMPP. Even if you're using GCM you'll have to implement a lot by yourself. In my humble opinion this is the best solution;
Implement a socket to connect the clients with the app server: this will required a whole lot of work, from sync to managing the power that your app consume, I wouldn't recommend you to follow this;
Understand the basics...
Extensible Messaging and Presence Protocol (XMPP):
Is a communications protocol for message-oriented middleware based on
XML (Extensible Markup Language).1 It enables the near-real-time
exchange of structured yet extensible data between any two or more
network entities
REST:
Is an architectural style consisting of a coordinated set of
architectural constraints applied to components, connectors, and data
elements, within a distributed hypermedia system. REST ignores the
details of component implementation and protocol syntax in order to
focus on the roles of components, the constraints upon their
interaction with other components, and their interpretation of
significant data elements.4 Through the application of REST
architectural constraints certain architectural properties are
induced: Performance, Scalability, Simplicity, Modifiability,
Visibility, Portability, and Reliability.4
From above we can understand that REST and XMPP are nothing more than protocols that you might end up using in order to pass your data through the components of your architecture. XMPP is the most optimized protocol for instant message communication, however, it is a bit more complex to implement. Fortunatelly, GCM support both protocols.
A possible architecture...
An instant message app is like any other client-server App. What is crucial to them is the need to notify the clients of updates that happen in the server. To do so, you need a proper way to communicate two clients. Usually this is made through a common app server. If you decide to go with GCM approach (my suggestion), you would have the following components:
GCM App Server: Responsible to manage the token generation and forward the received message to their targets;
Custom App Server: back end of the system implemented by you;
Client: web, android or iOS device that will receive push notifications;
It all starts when client opens the app, it will then make a call directly to GCM to request a token. Once it possess a token, the device should synchronize it with Custom App Server - so it knows everybody connected to the system and how to get to them. Custom app server maintain the token information in DB. When a device wants to send a message to another one, it will send a request to the custom app server which will, by its turn, retrieve the token of the target and forward the request to GCM App Server. It will then make a push to the target.
A Real Example...
As I said, I had to do a simmilar solution as I described above. The result of my work can be found in the following repositories:
Instachat Android: contains the source code for an App that uses GCM - it looks a lot like Whats App;
Instachat Core: a back end implemented using Spring Boot;
Both apps above were tested for a single one-to-one conversation using GCM and REST protocols, however, I'm still working on that and many bugs are present but the code can be used as a reference in order to understand the proposed architecture.
Hope I could help.

You can use GCM for sending and receiving messages.
You just need to send your messages to the receiving device through GCM, it will take care of it even if the receiving device is offline.

I used socket service for chat. so, I recommend you to use socket for
that. As compare to other, it will get quick response and all that you
want.

Related

How do I connect my Android app to backend?

I want to connect my Android App to the back-end. The aim of the project is to filter spam messages. So the app receives SMSs and then should forward it to server for spam filtering which uses machine learning. Now, the thing is we have a python program for machine learning but I don't know how to connect these two things - the Android app and the python program. Need guidance on how the app can send data(sms) and receive response(whether spam of not) to and from the server-side.
A common approach is to connect your client with a web backend that offers a web API (might be a REST API).
Here is a short overview over this topic: https://www.webiotic.com/api-for-mobile-apps/
What you need is a web server which can receive web calls and send back information. A web server in this sense is just a program which listens to incoming HTTP calls.
In your case, this might look like this:
The server is programmed to listen to web calls with the HTTP method POST on the route /checkMessage
It expects the message data in a certain format
For example in JSON with this content: {"message":"Your actual SMS message"}
the server checks its database or triggers a ML job
server returns a result in a specified format. For example this JSON: {"isSpam":true}
Your app then needs to send a POST call to https://www.[YOUR_URL]/checkMessage with the specified data and wait for a response
There are libraries for android which help you with that like Retrofit or OKHttp
As for which technology to use: It's up to you. You can create a web backend in pretty much every language. In your case, you should check out which Python libraries are available to listen to HTTP connections.
Keep in mind that if your app can publicly access your backend, then everybody else can as well. You will want to add some kind of authentication as well.

How to persist users(MultiUserChat) and chat history in Openfire (Ver 4.0.3) using SMACK API (4.2.0 Beta1)

I have successfully created a multiuserchat group, but the user goes offline the user is removed from the group, and i want to have the history of messages to save for the user the next time he logs in. I found some approaches from previous and deduced as follows
There are several old answers out there but none of them is based on new SMACK API 4.1.5+
using "Stream Management", but i have no idea what and how to do it, How it helps to solve my problem.
Using a PUBSUB for getting messages and delivering to user and showing the pseudo-list of users
I want to know the best and effective approach or any libs which help to achieve my result. I am a newbie to XMPP and have 2+ year experience in java
NOTE: I am looking for a whatsapp group chat implementation to kick/invite/providing_permissions to the user and history of messages for notifications/when he is offline.
I am searching for this from long time , Any Help is really appreciated.
Thanks in advance.
I think there are a couple of options:
You can try to prevent clients from leaving / disconnecting, or rejoining seamlessly, which is all pretty hard, and probably won't be possible to do completely right.
An alternative: The Openfire MUC implementation can be configured to send the entire history (or a configurable amount of last entries) when a participant joins the room. This is a crude way of retrieving all messages that were sent before you joined.
Another option is tapping into the history of a MUC room in another way: I think that the monitor plugin saves the history of a room to a database (or at least, should do this). Perhaps you can tap into that. If all else fails, you could create your own plugin, that does something similar: intercept all messages to/from a MUC server-sided, save them to a database, and allow clients to retrieve this history somehow.
With any solution, you should take into consideration privacy. When you're storing data, and make that retrievable, you should think hard on who is going to see what.
#hard-coder: Seems like you are viewing things from client side, while #guus proposed server side solutions. And as per your requirement: whatsapp group chat implementation server side solutions will work as it can't be done on client side.
WhatsApp has custom implementation of MUC on top of XMPP, so either you have to develop that in Openfire Server by customizing it. Or wait for the implementation of MIX in any server: Openfire, Ejabberd, MongooseIM.
Also take a look at MUC Light implemented by MongooseIM
If you want the solution, you can always get Business Edition of Ejabberd or MongooseIM which have the features you desire. But they are commercial solutions.
MUC is not full functional in openfire server. And use this to get chat history : Retrieve history chat Openfire XMPP framework
save messages and group names in database, when connecting to xmpp, connect to all groups from the database

Should I consider XMPP for any chat app

For a chat app, with extended features (not related to chat but realtime data) with support for Websocket and SocketIO based server, do I really need to integrate or consider XMPP. Isn't XMPP overkill for a simple file sharing (S3 storage), chat and other data communication (server status etc).
In my application, custom data is fetched from different storage, need to push to Message Queue in some event, and store uploaded file in S3. All these are not XMPP supported, So anyhow I will have to customize XMPP server implementations a lot if I choose it as backend.
Do you think I would be better off implementing all these by my own, compleletly skipping XMPP.
Or, is there anything in XMPP which I may have missed for considering it.
Support required in app:
Websocket
Long polling ajax
S3 storage
Redis / Aerospike DB
REST call to other services hosted on different machines
Android Client
iOS client
Windows client based on Qt
XMPP, formerly Jabber, is based on XML. I'm an old hand with XML, yet even I can see that it was chatty and redundant in creating open and close element tags, and also required a heck of a lot of open and close quotes.
What seems to be far more popular these days, especially in the NoSQL arena, are syntactically terser codifications of data such as JSON, or BSON (Binary JSON).
JSON: http://www.json.org/
Binary JSON: http://bsonspec.org/
Is there something specific in the schema, syntax, parsing or web-baed reification of XML which is a reason you want to use XMPP? Otherwise, you might find JSON an easier and more efficient way to encode data.
Also let me know if this answer was useful.

Messenger for browser and android - Comet, Lift server

My objective is to implement a messenger in a client/server model. However, in the clients, one client will be a web browser and another would be an android phone. So i need to develop an android app as well for a client.
For web server I intend to use Lift with Scala.
I wish to use Comet for messages in a fashion similar to described here
http://simply.liftweb.net/index-2.1.html#Next
Although this technique might work fine in web browsers, I don't think it will work on the android app.
What solution do I have for this?
How do messengers like whatsapp work?
Quickness in sending and receiving responses is an important factor here which is why I chose the Comet model ( and also its ease of implementation ).
However, I'm open to new suggestions and ideas for incorporating this functionality. Please guide me through....I'm also open to other languages for the server that may be better suited to the task since I haven't started development.
Ignite Realtime has a xmpp library for android (and you can use openfire as server)
http://www.igniterealtime.org/projects/index.jsp
here about gtalk/hangouts https://developers.google.com/talk/
You can do something like https://github.com/nafg/reactive/blob/v0.4.0/reactive-web/src/main/scala/reactive/web/SsePage.scala -- an implementation of HTML5 server side events in Lift for reactive-web.
You'll probably want to use Lift's RestHelper support to develop an API that your android app will communicate with. RestHelper (or any code in your application) can send messages to your actor, and can respond by executing any code - not just a partialUpdate. In terms of sending to the actor, while I don't have any concrete examples for you, these links may help you get started:
Sending messages to a named comet actor with REST
Sending messages using Async REST
Asynchronous REST Support in Lift

Android Application that displays new messages posted on a server

I am looking for reading resources or sample applications that can help me hammer out the following application workflow:
The client application establishes a connection to our server
The client application scans for updates on a regular interval
If an administrator has posted a new message, the new message is displayed in a widget.
I currently have 2 concerns:
I want to ensure that the monitoring service is not a major battery drain.
What is the most secure and simple method to establish the connection to retrieve data?
....There are a lot of suggestions out there... I need to know what method I should be researching over all others. Currently, all options are on the table because I have yet configure our server.
There are a lot of questions here, I'll try to give a succinct answer.
For the infrastructure I would go with HTTP REST calls to retrieve JSON data reprsenting your messages. Here is a decent link about writing an HTTP REST client for android, there are many others online.
For security, I would definitely start with SSL, but if you need to authenticate the requests I would also look at OAuth to secure you remote API.
As far as A, Have you considered using C2DM (aka "push") to trigger the updates? Then there's no client bandwidth beyond what is being used anyways for the Market/GMail/Talk connection. If you need to support Android versions below 2.2 it's not really an option at the moment, though.
Otherwise there's a few good examples of being a good citizen when polling from a widget; Jeff Sharkey's android-sky is probably the oldest, best, and most authoritative.
For B, unless I'm misunderstanding your need it's pretty hard to beat HTTPS; rolling your own "secure" transport over vanilla HTTP or anything lower-level is just asking for a disaster.

Categories

Resources