How to connect an Android phone to a web service on a local server?

I tried my emulator, it can connect to the java web service that I created. But when I try to access from my Android device, it will not work. Does anyone know how to get through this?

Another question is, is it possible that 2 Android devices have access to the same database?

I am using Tomcat server and MySQL database. The web service is actually used to retrieve data from a MySQL database and migrate to my Android phone.

Thanks in advance.

+4
source share
6 answers

Is it possible to start the service on your LAN-IP instead of the local host and connect the phone via Wi-Fi?

It is also possible to connect through the installation proxy.

+1
source

First, you need to make sure that your web service is displayed through the IP address of the machine on which it is located. You can verify this by trying to access the web server from another computer using the IP address and any port number that it can listen on.

If possible, then this should be the case when your phone is connected to the same network segment (router), on which the server is located, on which the web server is located, and use the IP (and port number) of the web server.

There should not be any problems on all Android devices accessing the same server, provided that the database is configured correctly and you are using the correct client code.

+1
source

Have you tried the IP address 10.0.2.2? This is localhost on the emulator.

0
source

you can try using the KSOAP2 library to access the WebService, google for now;)

0
source

You can get a public URL for your server running on a specific port on localhost.

At my workplace, I could access the local server using the local IP address of my machine in the application, like most other answers. But at home I could not do this for some reason. After trying many answers and spending many hours, I came across https://ngrok.com . This is pretty straight forward. Just download it from the folder:

ngrok portnumber 

(from the command line in windows)

 ./ngrok portnumber 

(from terminal on Linux)

This will give you a public URL for your local server running on this port number on localhost. You can enable and debug your application using this URL.

You can safely set your local web server on the Internet and fully monitor all traffic. You can also share the URL with a peer developer who can work remotely and can debug application and server interactions.

Hope this someday saves time.

0
source

When it works on an emulator, it should work on a real device. Perhaps this is a proxy or network problem.

For the second question. Are you using a local database for a client such as SQLite? If so, then each device has its own database, which must be synchronized with the server database (MySQL) through web services.

-1
source

Source: https://habr.com/ru/post/1441035/


All Articles