Connecting to localhost web server from android application

Dec 12

Written by: Goran Siric
12/12/2011 9:24 PM  RssIcon

To allow your application to connect to the internet first you need to do is to modify AndroidManifest.xml file to request INTERNET permission for your application.

To do this open AndroidManifest.xml file and add following line if not exists:

<uses-permission android:name="android.permission.INTERNET"/>

To connect to your local web server (localhost), you must use IP address of  your computer instead of localhost keyword or IP address. That's it because IP address is internally used by android emulator or your android device. 

Somewhere I found that you can use IP adress to connect to  your local web server. I tried it but this not work for me. I think that this depends of type of web server you have installed.

If you want to know more about connecting to the Internet from Android application you can read my blog entry: Android application and the Internet

4 comment(s) so far...


Great Info.

Great information you got here. I've been reading about this topic for one week now for my papers in school and thank God I found it here in your blog. I had a great time reading this.

By Caverta on   2/20/2012 12:26 PM

Re: Connecting to localhost web server from android application

I can't connect to your entry Android application and the Internet

By anoop on   7/8/2012 12:36 PM


I saw your entry& thanks for ur info

By anoop on   7/8/2012 1:10 PM

Re: Connecting to localhost web server from android application

The correct IP address to use to talk to the host running the emulator is I've abstracted communication with a webserver in my app behind this little nugget:

public static boolean isEmulator()
if (isDebug == null)
isDebug = "google_sdk".equals(Build.PRODUCT) ||
return isDebug;

public static String getServerUrl()
return (isEmulator() ? Constants.SERVER_URL_TEST : Constants.SERVER_URL_PUBLIC);

By Brian Krahmer on   11/26/2012 3:56 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 

Search Blog

If you found this useful,
you can buy me a coffe :)
By me a coffe through PayPal :)

Featured articles

Android "DataEntry ListView" Design Pattern

Have you realized the importance of ListView control in developing android applications ?

GIMP script for creating Android icons at once

Script for creating Android icons for different screen resolutions at once. Icons can be saved using standard Android icons naming conventions and saved in appropriate folders.

Creating Android button with image and text using relative layout

Source code with examples how to use relative layout to create nice buttons with text and images in Android

Android application and the Internet

Tutorial about connecting to the web pages on the Internet from Android application, using both POST and GET web requests.

Recent Entries

Calculated variables
Comments about Parking SMS Scheduler
Comments about cities and parking zones
Android "DataEntry ListView" Design Pattern
Android application and the Internet
Keep my DNN site alive

Recent Comments

ocean breeze recovery
Your site is really nice and unique. This is one of the best ideas that you had come up for the people and I do hope that they can have a better future.
Re: How to force Eclipse to rebuild generated resource class (R) in Android project ?
Forte School of Music is providing Music Lessons in Howick Auckland , New Zealand. Forte School is best in Music , Singing , Guitar and Piano Classes. Contact us now 09 534 2223
Re: Creating Android button with image and text using relative layout
Very useful. Thank you very much.
Re: Comments about Parking SMS Scheduler
Dear Peter,

currently I cannot provide you version without commercials, according to Google Merchant supported countries.

Re: Comments about Parking SMS Scheduler
I really like your app. But I don't like the advertisement page that now constantly appears.
Could you provide a pay-version of your app without commercials?