Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleartext http traffic to server.com not permitted

My code is working on android KitKat but it when running it in Pie gives io exception

Cleartext http traffic to server.com not permitted

I'm using volley to make server calls.

like image 755
RIK Avatar asked Oct 24 '18 11:10

RIK


People also ask

How do I fix cleartext HTTP traffic not permitted?

In the AndroidManifest. xml file, set usesCleartextTraffic property to true.

What does cleartext not permitted mean?

So what this exactly mean? Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with servers using a cleartext network traffic, such as HTTP, it could raise a risk of eavesdropping and tampering of content.

What is cleartext HTTP traffic?

Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with the server using a cleartext network traffic, such as HTTP, it could raise the risk of eavesdropping and tampering of content.

How do I turn on cleartext traffic?

If your application must support loading plain http:// URLs, you can opt into enabling cleartext traffic by using an AndroidManifest. xml file that includes an android:usesCleartextTraffic="true" application attribute.


2 Answers

First step is understanding why Google enforces you to use HTTPS. You can read more about it on the developers page.

As for how to fix it, there are two options:

1) Use HTTPS!

2) Create a new file in your XML folder named security_config.xml and add this:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

then in your Manifest file add this

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/security_config">

    </application>
</manifest> 

For obvious reasons, the second point is not recommended!

like image 131
Zun Avatar answered Nov 12 '22 17:11

Zun


Simple Solution:

Add this line in your manifest:

android:usesCleartextTraffic="true"

because I have faced the same issue with my php page for json api.

It should look like this:

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

Let's hope it works.

like image 31
ibad ur rahman Avatar answered Nov 12 '22 18:11

ibad ur rahman