Android server can't be reached from device - android

I am trying to access some php files that get data out of a local database.
The url is http://192.168.x.x/Foodlogging/getUserFromDB.php.
This worked perfectly in the emulator when I used 10.0.2.2.
I can access this url from my browser on my computer itself but not from the browser on the device.
I have this inside my manifest: <uses-permission android:name="android.permission.INTERNET"/>.
Both the devices are on the same network.
Any idea what I might be doing wrong?
P.S.: I am on my schools network and I know they have very strict firewall rules/settings, so might that be the problem? Like 1/100 I can access the url, the other times I can't.

Try turning off the mobile internet on the android phone, and leave Wifi on only.
This caused some issues for me when accessing local lan servers (usually 192.168.x.x).

Related

POST JSON without Internet with Genymotion

I have local database and Android app in Genymotion. I want to send POST JSON without internet. Both sides of code is ok on USB Device and database with WIFI connection. My database is written on ASP.Net web api 2 with azure functions.I tried to use different URL's
http://198.168.67.2:7071/api/LogIn
http://10.0.3.2:7071/api/LogIn
http://10.0.3.15:7071/api/LogIn
and nothing happened.
So, my question is: Can I send POST without internet using Genymotion and if yes how can I do this.
Thanks for help.
In order to do that, you'll need to connect the both desktop and your Android device (such as emulator or a real device) to a network which has a router.
Router will do the rest and it does not matter if it has internet connection or not.
So the solution will be that connecting both Desktop and the Android device to a local network which they can find the eachother.
Remember to add the Internet permission in the AndroidManifest.xml.
Check this link for more information.
This one.
And this one too.

How to give url in android

I have created a back end in Ruby on Rails and I am using url http://192.168.1.6:3000/products/4.json
where my phone is running with ip on the same gateway. http://192.168.1.somethign When I try connecting from android it gives the error unknown host exception. I also tried 10.0.2.2, which gives the same error. i tried running this url from the phone browser, and it says the webpage is not available. The phone is connected to the system using USB, both are in the same network using same wifi, I have also given the uses permission to access internet in the manifest file. How do I give the url now?
It is unable to resolve host, so I'm not mentioning the code, i shall add it if that helps.
After excessive searching and realizing the problem was not with the code but the reason was inability of phone and laptop to communicate properly. Still I could not fathom why? though they were in the same WiFi network. I solved my problem using this method . Putting it here for others reference,
1) Turn on the hotspot of your android phone
2) Connect your laptop to that network.(the hotspot).
3) Check the ipaddress now using ipconfig
4) Proceed using this ip address

Access local network from app while phone is acting as WiFi hotspot?

I'm writing an app that needs to be able to access the web server on my laptop. The phone I'm developing on is acting as a WiFi hotspot which my laptop is connected to. Everything is working fine if I try to access 192.168.43.16 in the phone's browser.
But the app I'm developing is not able to access the webserver for some reason. I'm guessing it's trying to use the 3G connection instead, which of course will not work. If I turn off mobile data I get an error message in my app saying that it can't connect to 172.30.253.241:8799, which seems to be my ISP's MMS server (?). That makes no sense to me, but maybe there's some caching going on here? Again, accessing my local webserver with Chrome in the phone works perfectly fine.
The app is using the "Android Asynchronous Http Client" by loopj, which is built on top of Apache's HttpClient. What can I do to make this work?
The reason I want to be able to access the local webserver is because it makes developing and debugging the server api used with my app a lot easier and faster than FTP-ing to my production server on the web.
Problem solved!
What I had to do was set the proxy of the AsyncHttpClient, using setProxy(), before making the request. I set the proxy address to the local IP address of my laptop running the web server.
client.setProxy("192.168.43.16", 80);
Now it seems to be working as expected.

How to access a URL on port 80 via android browser

my android device cannot access a URL:
http://myip:8080/alias
I tried another port of my service (80, running a service apache too) and works!
The tests, i'm doing from web browser of my device.
From my computer (on same network), both URL works!
The problem like a firewall. I cant access a port different of 80.
Thanks,
It's likely that the problem is related to your web service rather than your android device, as you should be able to access pages on non-80 ports without any issue.
Have you tried using fiddler or another debugging proxy to check the response from the server?
If not, this may be useful
http://fiddler2.com/documentation/Configure-Fiddler/Tasks/ConfigureForAndroid
Edit: also, you mention that you can view it on port 80 on your android device, perhaps try disabling your firewall on your PC?

is android emulator firewall safe from firewall(e.g all internet logs will go in encrypted form)?

I am confused with this thing, is emulator safe from pc network's firewall like no one knows what we surf? I want to know on this, does anybody know about it?
All requests made by the emulator are just like requests made by any other app. If you access a HTTPS website on your emulator, the data will be transmitted encrypted, just as it would be if you used your computer's browser.

Categories

Resources