简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM