title: Android 9: Cleartext HTTP traffic not permitted although having cleartextTrafficPermitted="true"
body: <p>I have a strange issue. My app is using http to connect to a server. It works fine in many devices. However, in Xiaomi devices which has Android 9, it gives me this error:</p>
  
  <pre><code>Caused by java.io.IOException: Cleartext HTTP traffic to internet.vodafone.com.eg not permitted
         at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:142)
         at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:469)
         at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:418)
         at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:549)
         at com.google.firebase.perf.network.zzd.getResponseCode(zzd.java:81)
         at com.google.firebase.perf.network.zzb.getResponseCode(zzb.java:14)
         at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:96)
         at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
         at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
         at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
         at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
  </code></pre>
  
  <p>In the AndroidManifest.xml I have this:</p>
  
  <pre><code> &lt;application
          ...
          android:networkSecurityConfig="@xml/network_security_config"
          ...
    &lt;/application&gt;
  </code></pre>
  
  <p>My network_security_config.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;network-security-config&gt;
      &lt;domain-config cleartextTrafficPermitted="true"&gt;
          &lt;domain includeSubdomains="true"&gt;thebondnews.com&lt;/domain&gt;
      &lt;/domain-config&gt;
  &lt;/network-security-config&gt;
  </code></pre>
  
  <p>Also, I have all the permission to connect to the internet. It works fine in Many devices with android 9 Like Samsung galaxy s9/s9+ and Samsung galaxy s8/s8+ and many others.</p>
  
  <p>The error message was copied from Firebase Crashlatics. What is strange is that my server domain is thebondnews.com but in the log, it says <code>internet.vodafone.com.eg</code> or sometimes <code>notification.etisalat.com.eg</code> and <code>10.10.10.1</code>. It is like there is kinda redirection in their devices.</p>
  
  <p>Can anyone help me how to solve it? or what shall I do?</p>
  
  <p>Update 1:
  Could it be that I am only allowing my domain in <strong>network_security_config.xml</strong>
  and because of the redirection caused by their providers the connection fails?</p>