How to Connect Android App with a Local Web Sever [Localhost] using Tethering/Portable Hotspot


When developing and testing apps that make calls to a web server (e.g mysql data storage ), you’ll likely need a  connection between your android device and a web server running on your PC.  Existing approaches have tried to explore creating adhoc wireless connections on a PC or installing virtual routers. These approaches do not work very well … and I really wanted to avoid the hassle of exposing my traffic to 3rd party wireless router software. Turns out there’s a simple solution –  create a wireless hotspot on my android device and connect my PC to it. Worked like a charm.

While the android hotspot feature was created mainly to share a mobile data connection with other devices (tablets, gps, pc), it will also function as a “wireless router”. You can simply turn off “Data” on your device if you don’t want to share your data plan . I am currently testing this on a device without a SIM card. Works just fine.

Note: If you already have your android device and your pc connected on the same local network (i.e you can successfully ping your mobile device from your pc), they you may just skip to the last step.

1. Create a Tethering/Hotspot Profile on your android Device

On you device, got to Settings > Tethering / Portable Hotspot. It’s a good idea to name your network and give it a password to discourage random people from connecting to .

Screenshot_2015-06-13-13-03-04 Screenshot_2015-06-13-13-03-34

2. Connect your PC to your Android Hotspot

Your hotspot should show up on your list of wireless connections on your pc – connect to it and provide the password you setup earlier.

3. Access your PC/Localhost from Your Android Code

First you need to get your PC ip address . You can go to your command line and run ipconfig, check your wireless interface to get your ip address. Your address should likely be of the form 192.168.xx.xx . You can then use this address to access your server in android e.g

HttpGet httpGet = new HttpGet(“”) ; 

A more detailed tutorial on storing and retrieving data from a mysql database can be found here.

Did this work for you ? Share your experience below.

About Vykthur

Mobile and Web App Developer and Researcher. Passionate about learning, teaching, and recently - writing.
This entry was posted in Android Tutorials and tagged . Bookmark the permalink.