Reputation: 157
I'm working on a project in which I need to communicate between an Android device and a computer. To initiate a connection between these two device I thought using a Rest API mechanism with the following architecture :
My current flutter snippet looks like :
Jaguar server = Jaguar(port: 8080);
server.get("/", (context) => 'Hello');
await server.serve();
When accessing to "localhost:8080" from a web browser directly on my Android device, I get the "Hello" message but when trying to do the same thing from my computer (which is on the same network), I get a timeout error (on "192.168.0.10:8080").
It seems that my flutter (or my device) does not expose the web server to the rest of my network but I don't know why.. Do you have an idea ?
Upvotes: 1
Views: 822
Reputation: 4470
My solution was to bind the server to 0.0.0.0
instead of localhost
.
Upvotes: 1
Reputation: 157
After a while, I found the solution. It's because since the API 28, Android blocks clear text traffic.
To solve this issue, we must override android:usesCleartextTraffic="true"
like
<application
...
android:usesCleartextTraffic="true">
...
</application>
Upvotes: 2