I am making an application that uploads images to server and updates its database to server in android while executing it, it shows an error
Connection to ht
Two solutions for this error:
1. add this permission in your androidManifest.xml of your Android project
<uses-permission android:name="android.permission.INTERNET"/>
2. Turn on the Internet Connection of your device first.
i was facing exactly the same issue and i made following changes to my URL after which it was working perfectly fine..
From:
http://localhost/Image4android/get_all_images.php
To:
http://192.168.1.2/Image4android/get_all_images.php
where the ip: 192.168.1.2 is IPv4 address. In windows Run > CMD > Ipconfig
I am using PHP for webservice and Android 4.x. device for connecting to the webservice. I had similar problem where, using 10.0.2.2
worked well with emulator but failed to connect from device. The solution that worked for me is: Find IP of your computer ... say 192.168.0.103
Find the port of your apache ... say 8080
Now open httpd.conf and locate following line Listen 127.0.0.1:8080
After this line add following Listen 192.168.0.103:8080
Thats it. Now if you use 192.168.0.103:8080
in your android code, it will connect!!
if you are using emulator to run your app for local server. mention the local ip
as 10.0.2.2
and have to give Internet permission into your app :
<uses-permission android:name="android.permission.INTERNET" />
When you test with device you want to add your PC ip address.
in pc run in cmd Ipconfig
in ubuntu run terminal ifconfig
Then use "http://your_pc_ip_address:8080/register"
insted of using "http://10.0.2.2:8080/register"
in my pc = 192.168.1.3
and also add internet permission to Manifest
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
try adding the permission outside the application tag of the manifest in addition to the above mentioned answers of changing localhost to 10.0.2.2:8080