Running a ruby on rails project on my mac. I need to test it on my android phone. Is there a way to view my mac localhost on my android phone?
You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".
Jump to step:Connect both devices to the same network. Find the IP address of your computer. Find the host name of your computer. Open your mobile browser and visit the IP address or host name.
On your mobile device's browser (any will work), navigate to http://<Local IP Address>:<port number> . For example, if I was serving on localhost:8080 and my local IP address is 123.45. 67.890, on my mobile device's browser I would navigate to http://123.45.67.890:8080 . The http:// is important, don't leave it off.
The name "localhost" is just a loopback to your own computer. To access it on your Android, you need to find the computer's IP address.
The most general way of finding this info, which works on both Mac and Linux, is to go into the Terminal and type ifconfig
. Look for either "en0" or "en1", and under that entry look for the "inet" listing. It will be something along the lines of "192.168.1.100". When you find that address, that's what you'll want to put in your browser's address bar.
(On a Mac specifically, you can go to the Sharing pane in System Preferences and it'll tell you there.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With