Android Device Connection to WAMP Server

If you need to connect your Android phone/physical-device to a local (PC) WAMP server, then you’ll need to fulfill the following points.

Proper URL
In your android app, make sure that the URL you’re using to connect to the server is not "http://localhost/your-desired-resource..." but corresponds to the actual local (router-assigned) IP of your server/PC. You can get that information by logging in to your router at 192.168.1.1 and looking for a clients table containing the IP addresses of all connected hosts/machines.

For example, if the local IP of your PC (running the wamp server) is 192.168.1.101, then the URL to use in your app’s REST client will be "http://192.168.1.101/your-desired-resource..." where your-desired-resource is the server resource/file that you want to retrieve.

Enable WIFI
This point is simple but not so obvious. It turned out to be my missing piece; yet, it took forever to find!

You need to enable WIFI on your android device and connect to your local network! Without WIFI, you’re going to receive a “BAD REQUEST” from the local server. No Apache configuration (that I know of or have tried) will save you from this. Ultimately, both the PC and the Android device need to be connected to the local network. This means that if you’re coding at home and have a wireless router, connect your phone to the wireless network!

I blindly assumed that networking would occur via the USB cable and this is not the case. I’ve seen people recommend turning on USB Tethering; however, that option disables USB debugging and prevents the uploading of your app to the device.

Hope it helps!

Comments

comments