11

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

isuru
  • 535
  • 1
  • 9
  • 25
  • If you change `android:usesCleartextTraffic="true"` in network_secrity_config.xml, Android Studio complans like `Setting is not recommended.` Recommended way to add this permission with related Domain. Check this [Link](https://stackoverflow.com/a/58898167/1744705) – TeachMeJava Jan 14 '20 at 13:14

3 Answers3

15

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!!

isuru
  • 535
  • 1
  • 9
  • 25
Shivam Oberoi
  • 1,447
  • 1
  • 9
  • 18
  • why this line android:networkSecurityConfig="@xml/network_security_config" along dosent work – isuru Jan 14 '20 at 10:30
  • @isuru I had the same problem. inside the network_security_config file get rid of the http:// part in the domain AND it worked for me – i_o Aug 18 '20 at 20:11
1

Try with below security config code

<?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>
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
0
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>
eagerprince
  • 115
  • 1
  • 5