I'm able to access my laptop web server using the Android emulator, I'm using 10.0.2.2:portno
works well.
But when I connect my real Android phone, the phone browser can't connect to the same web server on my laptop. The phone is connected to the laptop using a USB cable. If I run the adb devices command, I can see my phone.
What am I missing?
use
connectify
andxampp
or equivalent, and type ip address on mobile URL bar to accessRun CMD as administrator
and on CMD screen type ipconfig and the screen will appear with text
as this photo
and you can access your localhost using this ip you have to be connected to same network as your pc connected to
Adding a solution for future developers.
Copy address of your ip address. right click on your network -> network and sharing-> click on the connection you currently have-> details-> then the address beside ipv4 address is your ip address, note this down somewhere
Go to control panel -> system and security -> windows firewall -> advanced settings -> inbound rules -> new rules (follow the steps to add a port e.g 80, its really simple to follow)
put your ip address that you noted down on your phone browser and the port number you created the rule for beside it. e.g 192.168.0.2:80 and wala.
Possible solution if it doesn't connect. right click network->open network and sharing-> look under view your active connections, under the name of your connection at the type of connection and click on it if it is public, and make sure to change it to a home network.
Try going to this file:
C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
And change 10.0.2.2 to your IP address.
I used this process:
Note that this process requires you to change the WiFi settings on the Android device at the start and end of every session. I found this less painful then rooting my Android device.
First of all make your machine(where server is running)IP address static. Enter this static IP address in the android code. Next go to your wifi router's interface and check the left panel. You will see option such as port forwarding/forwarding. Click on it and forward port 80. Now edit your
htttpd.conf
file and edit it forAllow from All
. Restart your server. Everything should work fine now.
Additionally you can reserve the IP address of your machine so that it is always allocated to you. In the left panel of your router's interface, find
DHCP -> Address Reservation
, click on it. Enter your machine's MAC address and the IP address you have entered in the code. Click on save. This will reserve the given IP address for your machine.