I am new to android and java. I am trying to develop a test app which gets data stored in local database. I am using WAMPP. In emulator I can access it perfectly, but when I try to access it in my physical device (Micromax A311) I get java.io.FileNotFoundException. I have seen many questions asked for this question, but none worked for me.
In my AndroidManifesti have added following code
<uses-permission android:name="android.permission.INTERNET"/>
Url
String url="http://192.168.0.104/selectQuery.php";
which is my IP4 (Wireless LAN adapter Wi-Fi) address.
I have tried it with
http://10.0.2.2/....
/10.0.2.2:80/....
/192.168.0.104:80/
I can access data in browser saved in my database using
/192.168.0.104/ and /192.168.0.104:80/
I am connected physical device via USB to laptop. In my tethering setting I turned USB tethering on.
I am connected with same WiFi which is connected to my laptop.
My proxy setting of laptop is also off.
Can anyone help me to get out of this problem.. I am struck in this from past few days..
Thank you
If selectQuery.php file is in a folder your url is like:
String url ="http://192.168.0.104/name_folder/selectQuery.php";
So if have ./myFolder/selectQuery.php the url is:
String url = "http://192.168.0.104/myFolder/selectQuery.php";
Thanks for your reply... I found a solution myself. I downloaded https://ngrok.com/download, then used its CMD and copy pasted
ngrok http -bind-tls=false site.dev:80
which i found in https://ngrok.com/docs#bind-tls under Tunneling only HTTP or HTTPS. Then I used forwarding address in my url string.
It worked Fine.. I am happy now..
Related
Error & Codes
My codes and error are in that link of picture "Error & Codes"
Hi everyone, you all doing well,
Im having a problem about WebView, i have tried many ways but I'm still getting this err_connection_refuse error and i cant solve it. Can anyone see what my problem is ?
I'm trying to use this way to show the world map in that web address on my phone but if there are any suggestion, I'm open to it.
(Android Studio 4.0 + Java + API 28 + Blacked URL address due to company policy )
Thank you :)
IMPORTANT NOTE :
That site can only be reached with VPN (i can reach it from web browser on computer) but i have installed cisco anyconnect VPN to emulator and secured connection too.
I´ve set up a samba server on a Mac with OS X El Capitan.
Then, configured my java project to access this server using jCifs library but I get this error:
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password
My code is:
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain","username","password");
String path = "smb://ip/filepath";
SmbFile file = new SmbFile(path, auth);
The username I used is the owner of the account in which I set up the server in the Mac and the password is correct.
I tried to access from another Mac and from an android device, both in the same network. I Also tried creating another user account in the server, with no luck.
In google, most of the cases belong to other OS. Besides that, my configuration seems fine.
Any idea? Thanks in advance.
After a deeper research, I found a post in which is told that the smb protocol implementation seems to be broken in OS X (link here: http://www.tweaking4all.com/os-tips-and-tricks/macosx-tips-and-tricks/smbup-mac-os-x-smb-fix/).
The server was set up using the configuration tool provided by the operating system so I tried to reconfigure the server with the same settings than before using other tool (SMBUp) and now I can connect without any problem without having changed the code.
While I access the localhost servlet from android httpclient utils I am getting connection refused error. The servlet is running fine, but I am getting error.
This is the code:
String dmurl="http://127.0.0.1:9090/DataManagerProject/DMServlet";
HttpClient httpClient = new DefaultHttpClient();
HttpGet hrtreq = new HttpGet(dmurl);
HttpResponse resp = httpClient.execute(hrtreq);
String output = EntityUtils.toString(resp.getEntity());
I am getting following error org.apache.http.conn.httphostconnectexception connection to refused
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
For more details, please refer this link.
Also, Turn Off the firewall and any anti-virus application in your PC
Check whether you have internet access enabled in your emulator and in your application
<uses-permission android:name="android.permission.INTERNET"/>
To access internet data of the device or emulator from your application add the above line in your manifest xml file.Also check the servlet mapping is proper in your the servlet project.
Assuming your servlet runs on your computer the reason you can't get a connection is because your using the wrong IP. 127.0.0.1 is a loopback address meaning that if you connect to 127.0.0.1 on your Android device, it will try to connect to the Android device.
To make it work you have to find the IP address of the computer which runs the servlet and use that in the URL instead.
In addition make sure you have given the Internet permission to your app.
my android application communicates with .Net webservice.
i communicate with the web service using the ksoap2 library.
i see that in every time i activating method in the webservice its taking too long.
i debugged to the HttpTransportSE.call() method and i see that in the InetAddress.getHostByAddrImpl(byte[]) method there is an unknown host exception trowed after something like 20 seconds...
its strange because my url is an ip address and there is no dns lookups needed...
this exception trown even when im running this code:
InetAddress.getByName("192.168.191.110").getCanonicalHostName();
can some one explain me how to fix this?
thanks!!
Maybe you forget to add permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
EDIT
Try also this:
java.net.InetAddress[] x= java.net.InetAddress.getAllByName("192.168.191.110") ;
textView.setText("Address: "+x[0].getHostAddress());
I find that my sim card cannot access none of the available dns servers.
so i worked with the system/etc/hosts file and added the mapping there.
before the application is asking the dns server for the address there is a check of the system/etc/hosts file.
after i added the mapping there all worked well.
thanks for the help.
To use IP address you have to use getAllByName() instead of getByName(). See docs here.
So replace
InetAddress.getByName("192.168.191.110").getCanonicalHostName();
with
InetAddress.getAllByName("192.168.191.110").getCanonicalHostName();
I have android application which connect to "hosturl" over the web. This application can connect to hosturl in the initial steps, but after i try to test it for some time(say 20 or more requests), I get above exception and I can not no longer connect to above url.
If i restart my android handset, then application can again connect to the "hosturl" but again I get the exception after I have tried to connect to hosturl few number of times
Could anybody help me here If you have encounter such a behavior with an android application before.
You probably don't have the INTERNET permission. Try adding this to your AndroidManifest.xml file, right before </manifest>:
<uses-permission android:name="android.permission.INTERNET" />
I met this and I just closed my AVD and start it again and it worked...
Check your Internet connection.
Check Wifi.
Check Server.