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 :
- Rest server : Android Device by using https://pub.dev/packages/jaguar
- Rest client : my computer by using Python
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 ?
CodePudding user response:
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>