droidH
droidH

Reputation: 39

Android device won't connect to local server

I made an app that connects to a php file. The code is working using the AVD without a problem. Now when I tried the app in my android device it force closes. My android device is connected through a wifi network. I'm using wamp server on windows 7.

I have pinpointed the problem but I cannot resolve it. I'm hoping one of you good guys can help me. This is my culprit (192.168.1.100 is the machines IP):

private static String url_all_products = "http://192.168.1.100/android_connect/get_all_products.php";

How can this be solved? 100% working in AVD but won't work in actual android device.

Upvotes: 0

Views: 16374

Answers (4)

ramakrishna konda
ramakrishna konda

Reputation: 21

  1. Try to connect your mobile to the same network as your computer. I used virtual router to make my mobile in same network as my laptop
  2. Then use ip address of your computer to access your computer web server from your mobile.

Upvotes: 0

averasko
averasko

Reputation: 970

Do this:

  • first, put both your android device and your computer into the same network as described here
  • then, make your device connect directly to your computer via its IP in that network (find the IP as here)

Upvotes: 0

Sanjay Kumar
Sanjay Kumar

Reputation: 1474

You need to check two things :

  • Your external IP address i.e if you are using windows use command "ipconfig" and get IPv4 address.
  • Check you permissions in AndroidManifest :
uses-permission android:name="android.permission.INTERNET"

Also check : https://stackoverflow.com/a/16510143/644011

Upvotes: 1

maddy
maddy

Reputation: 205

@droidH if you working on local server change your url to 10.0.2.2 to your IP address

go to this link it works
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

Upvotes: 1

Related Questions