0

When i am using URL with http then it shows an error "CLEARTEXT communication to (domain name) not permitted by network security policy" . I have tried cleartextTrafficPermitted = true in manifest.xml file but it is not compatible with payment gateway i use, which need cleartextTrafficPermitted = false. As it is API level 23 so, networkSecurityConfig = "@xml/network_security_config" doesn't work in it. I am using Retrofit as networking Library.

It is device specific issue Xiomi Redmi 3S, MIUI Global 10.2, Android version 6.0.1.

Any suggestion about this issue.

Rahul Khatri
  • 1,502
  • 2
  • 13
  • 25
  • The error message clearly shows that the networkSecurityConfig is active. As you don't provide a custom on the system default networkSecurityConfig is used. Therefore provide your own networkSecurityConfig, it will be used if the device is running API23 or higher. – Robert May 09 '19 at 12:34
  • I have used networkSecurityConfig and it working for Android Pie, but not in my Redmi 3S device. – Rahul Khatri May 09 '19 at 12:39
  • Possible duplicate of [Android 8: Cleartext HTTP traffic not permitted](https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted) – Zoe Jun 14 '19 at 19:27
  • It is different as Android 6.1, network file does't work, issue specific to Xiomi with MIUI Global 10.2 can you give any suggestion for this issue. – Rahul Khatri Jun 17 '19 at 04:54

1 Answers1

1

Finally i got solution by medium post , Code i used :

  • Step 1: create file : res/xml/network_security_config.xml Add code in this file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">Your URL(ex: 127.0.0.1)</domain>
    </domain-config>
</network-security-config>
  • Step 2: Add line in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:networkSecurityConfig="@xml/network_security_config"
        ...>
        ...
    </application>
</manifest>
Rahul Khatri
  • 1,502
  • 2
  • 13
  • 25