I’m developing an app to download files from the Internet. It works flawlessly in Android 7 and below, but stops downloading files in Android 9 and above, showing the following error:
<code>java.net.UnknownHostException: Unable to resolve host "https://example.org/file": No address associated with hostname
</code>
<code>java.net.UnknownHostException: Unable to resolve host "https://example.org/file": No address associated with hostname
</code>
java.net.UnknownHostException: Unable to resolve host "https://example.org/file": No address associated with hostname
I know that in Android 9 and above, I have to set Network Security Config
in res package, then create xml package and in xml package create new xml resource file with network_security_config name. So this is what I have done:
- Adding
android:usesCleartextTraffic="true"
andandroid:networkSecurityConfig="@xml/network_security_config"
to application tag in AndroidManifest.xml - Creating
res/xml/network_security_config.xml
with this content:
<code><network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
</code>
<code><network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
</code>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
But still no luck. Any idea or suggestion will be gladly helpful.