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.
Related
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.
I'm writing an android app that uses GPS. It sends the NMEA string in a JSON object back to a django app I've already written (for similar use with an arduino+GPS). In order to send the data, I'm using sockets (the socket connection is on a intentservice, the gps code on a regular service).
The sockets are handled by the python tornado webserver, which receives the json object and adds the data to a PostGIS database with the appropriate django model, while still letting me browse the app from a browser like you would normally.
These are both my first android and django apps and I'm looking to improve them as well as my own coding/knolwedge of both platforms.
I'm just wondering if there are better, smarter ways of accomplishing these tasks.
Have a look at this third party rest framework (DRF): http://www.django-rest-framework.org
Gives you a django side solution out of the box. There are others (tasty-py) but in my opinion DRF is the best there is.
No need to do anything with sockets i suppose...
I am going to create game for android, this game has multiplayer mode, so it should send ang get some data from server.
Lets assume that 5 players are playing this game.
Each player on his turn sends a word to server, server checks if this word is correct and then server sends this word to other players.
Also server has some kind of timer, and when times goes out it sends to all player then time is up.
Very simple.
Now what is my problem. I have never done web programming and I don't know how to implement server side. Google gived me several options:
Http server
Sockets server
What should I use? One of this options or something else?
Also what frameworks/libraries can be helpful in implimentation? I'd prefer python (like CherryPy if http server is good for my purpouses), but also I can do it on java or c++. Or on php (but I don't want to use it)
Update
After thinking for a while I used python tcp socket server. It seems to be most lightweighted solution for my needs. Also it is easy to interact with it from Java.
Consider using Twisted Python and roll your own simple protocol using persistent connections.
Alternatively, use a normal HTTP(s) server like Apache or nginx and WSGI to tie in your python backend logic. To make it appear as if you have a persistent connection (used to notify everyone of the "word" that was submitted or the expiration of a timer), you'll need to use something like AJAX.
Have you considered using parse?
https://parse.com/
Another good option I like is NodeJS, however you will get alot of the same benefits such as Asynchronous Concurrency from Tornado (Python)
I have an app in android,a kind of client-server in which the client has stored some gps data in Sqlite database and once connected with server it delivers it that data which at its turn stores it in it's own database for future manipulation!
Now the problem is that I have to create a server that accepts multiple clients and I cannot find a decent example in this way.I'm not using no services in combination with it!
Both my client and server are on android!!!!
I have already did the connection between client and server,but only with one thread(I mean my server can accept only one client at this moment!)
Is this suitable?
How to implement simple threading with a fixed number of worker threads
Thank u in advance!
If server is Microsoft based, .net web service can be used that can be accessible from multiple Android clients and work with database.
Your server is not on the Android device I guess, so I don't think the question is android related.
Check out this example of multithreaded server in Java and this one as well.
To communicate with database, see the Java JDBC tutorial.
Those examples are in Java, because that's what I am used to, but any other language will fit as well.
A simple POST request from the client to the server should be good enough. Encode the data in a suitable format (JSON/XML) and send it as a POST HTTP request.
I don't understand why you want to write your own server. I would just use a PHP/Python script running with Apache to receive the POST request and store the data in a database (MySQL, PostGre).
On your Android device, you should put all your code in an AsyncTask. Android uses the standard Apache libraries to make the HTTP request.
I'm planning on writing an android app that can view and update data on a local network Oracle DB.
I have already written a python script which checks the oracle db every couple of minutes and writes out XML files which I then plan to parse through my android app to display the data.
As I mentioned though this will only work if the android device is part of the same network (either connected locally or through a vpn), and the XML will be stored on a Unix server.
The question is how to access that Unix server with the android app? Can I use FTP via an android app, or should I be looking to change the python script to send the XML to an easily retrievable location?
EDIT To clarify what you mean, you have a web service running on something like tomcat, the client sends a request to get the data from the oracle db (can also use some form of authentication), the web service responds and sends the data in a format (XML, JSON etc.), the client then sends a request back to the web service to change some data on the oracle db, and in turn it does the clients bidding?
Normally you would create a web service to provide data to mobile clients. There are several reasons for this:
Web services are accessed via HTTP/HTTPS which is a standard protocol and is guaranteed to work on all networks. Corporate wifi networks are especially notorious for locking down protocols except for web and email.
Web services compared to static XML files have an advantage of creating response on the fly. Which means that data will be current.
Web services can take some input parameters and create response based on this parameters.
Authentication: it is a common approach to implement username/passord authentication in the web service, especially if you serve some private data.
Update:
REST is a very popular type of web service. Look at some implementations in Python: Recommendations of Python REST (web services) framework?
This book helped me a lot: http://oreilly.com/catalog/9780596529260
REST is a way of designing your web service. Folks much more intelligent than you and me have divined that all of the work needed for something to work on the net can be handled through a combination of HTTP status codes, HTTP verbs like POST, GET, DELETE, PUT etc. and a clear hierarchy of resources (nouns). It sounds very limiting but it's quite beautiful when it all works together.
Have a look at the Facebook Open Graph API (developers.facebook.com) to get an idea of what a proper REST service looks like.