devstepbcn / react-native-android-wifi

A react-native module for viewing and connecting to Wifi networks on Android devices.
ISC License
212 stars 121 forks source link

wifi.forceWifiUsage is not working #85

Closed jothikannan closed 5 years ago

jothikannan commented 5 years ago

Platform : Android 9 "react-native": "0.60.0", "react-native-android-wifi":"0.0.41"

Can anyone help me to fix this? I am not a java guy so struggling with this issue for past one week.

Note: This is only happening on release-build of the app only, debug-build it is working fine.

jothikannan commented 5 years ago

Finally found the issue, if anyone uses localhost or http requests after forceWifiUsage, please keep in mind Starting with Android 9 (API level 28), cleartext support is disabled by default. So do following

Create file res/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">Your URL(ex: 127.0.0.1)</domain>
    </domain-config>
</network-security-config>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

Actually wifi.forceWifiUsage is working fine, but as i said Android 9 (API level 28) is refusing the calls from http protocols

btav commented 4 years ago

@jothikannan thanks man you saved me! We should probably include this in the docs.