Solution 1 :
You need to be on the same wifi-network on both laptop and mobile. Plus the IP should be same as of laptop’s.
Solution 2 :
If you are not using SSL, you will have to enable Clear Text Traffic on your Manifest file:
<application
...
android_usesCleartextTraffic="true">
Problem :
I am running several services on my local laptop which uses a range of ports. Everything is working when i’m using my android emulator on the laptop and i decided to test it using a real android device.
I’ve rooted the device and updated its host file to have the server url (used when during fetch calls) to point to my laptop’s ip address, similar to what i’ve done on my android emulator. I am able to hit the endpoints through my browser but it doesn’t work on my app (Network request fail). As such, I tried to hit the endpoints using a REST tester on android (RestClient) but it timeout-ed. I am using HTTP requests so far, so the SSL verification shouldn’t be a problem here.
I am also doubting that the timeout is due to speed issue since the wifi speed of my devices isn’t too bad?
I am confused as to why my browser on the Android device is hitting the endpoint but my app isn’t able to? When using postman/emulator on my local computer (where the services are hosted), everything is working fine too.
Any help will be appreciated, thank you!
Some other info about my Android device:
- Galaxy Note 5, Android Version 7.0 & rooted
Comments
Comment posted by Rohan Pawar
have you added internet permission in manifest?. please your https request code
Comment posted by kito
@RohanPawar yep i have it! This line is inside my manifest:
Comment posted by kito
@RohanPawar i’m actually fetching a HTTP url, which works on my local computer’s browser,postman & emulator as well as my android device’s browser so i have a feeling the fetch method and url is not the issue?
Comment posted by kito
hello, thanks for the reply! I made sure that they are in the same wifi-network! I am not sure what you mean by the IP should be same as the laptop’s. What i’ve done is edit the /system/etc/hosts file to point to that ip address for the url used in the fetch call. As such, i can hit the endpoints on the browser of my phone, but weirdly not on the Rest Client app.
Comment posted by kito
hey there, thanks for the reply! I’ve already included this but it wasn’t working 🙁
Comment posted by Helton Malambane
@kito If you can reach the endpoint on the phone’s browser means your network connection is ok. Can you please post your error stacktrace? Maybe there could be a problem with the returned content-type and it fails to parse.