I’m new and haven’t been able to solve the problem for several days now. There is a device on the local network (smart home) that I can turn on and off from the browser without problems using a get request (http://192.168.0.100/Power?Power=1). I’m writing an application for Android, everything works fine in React Native in the emulator, but after installing the app on a real phone, nothing works anymore. Please help me figure it out.
const test = () => {
fetch('http://192.168.0.100/Power?Power=1', true)
};
return (
<TouchableOpacity
onPress={() => test()}>
</TouchableOpacity>
)
2
Answers
Answer:
There are a few possible reasons why your React Native fetch HTTP request might not be working on a real phone
I think you need to use Axios to make a fetch request the below code is helping you
And I think you need to check more first
If you are still having trouble, please provide more information about your setup and the error messages that you are seeing.
I had a similar problem. Here is my solution:
To switch a smarthome-device I can send a http-request with any browser:
http://192.168.178.101/relay/0?turn=toggle
But the attempt to write an app with android studio failed.
I tried every library: the old apache, okhttp3, khttp, fuel and volley.
Here a very short code snippet with volley. This works fine with an http-adress in www, but not in my home network:
I added all thinkable permissions to androidmanifest.xml:
Astonishing, that the app works on my old smartphone with android 8!
When comparing the Android versions I found this helpful thread:
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?
After insert this line to androidmanifest.xml it works !!
(Alternativ you can downgrade your sdk in gradle to targetSdk = 26, but that is only a emergency solution)