Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLEARTEXT communication to XXX.XXX.XXX.XXX is not permitted by network security policy [duplicate]

Tags:

java

android

This is the Manifest file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

<application
    android:usesCleartextTraffic="true"
    android:name=".Dao.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".FoundActivity"></activity>
    <activity android:name=".LPcapActivity" />
    <activity android:name=".RentActivity" />
    <activity android:name=".MPxtActivity" />
    <activity android:name=".LPanActivity" />
    <activity android:name=".LDtileActivity" />
    <activity android:name=".TabActivity" />
    <activity
        android:name=".MainActivity"
        android:noHistory="false">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.stk.android.compapp.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

I have created XML file(network_security_config.xml) under XML folder

enter image description here

    <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">http://121.345.678.90:7744/KBB/Kbblist</domain>
        <domain includeSubdomains="true"> http://111.234.177.123:1100</domain>
    </domain-config>
</network-security-config>

I tried with options available in this link also
android-8-cleartext-http-traffic-not-permitted
Still, I will get this error which is saying CLEARTEXT communication is not permitted by the network security policy

like image 818
isuru Avatar asked Jan 14 '20 10:01

isuru


People also ask

How do I fix cleartext HTTP traffic not permitted?

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

What is cleartext not permitted?

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.

How do you fix cleartext traffic for all domains?

you cannot allow cleartext traffic as the default. this is what occurs when you add the cleartext macro to your manifest. you have to remove that line from the manifest and create your own network security config file. in it you will add a list of url's for which your app permits cleartext.

What is cleartext communication?

Cleartext is transmitted or stored text that has not been subjected to encryption and is not meant to be encrypted. As such, cleartext does not require decryption in order to be displayed. In its simplest form, cleartext is rendered as ASCII that can be read by any word processor or text editor.


1 Answers

Just add this in application tag in your manifest-:

android:usesCleartextTraffic="true"

Here

<application
    android:usesCleartextTraffic="true"
    android:name=".Dao.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:usesCleartextTraffic="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

I hope it helps!!

like image 77
Shivam Oberoi Avatar answered Sep 24 '22 09:09

Shivam Oberoi