This question already has answers here:
Android 8: Cleartext HTTP traffic not permitted

(33个答案)


去年关闭。




这是 list 文件
<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>

我已经在XML文件夹下创建了XML文件(network_security_config.xml)

java - 网络安全策略不允许与XXX.XXX.XXX.XXX进行CLEARTEXT通信-LMLPHP
    <?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>

我也尝试了此链接中的可用选项
android-8-cleartext-http-traffic-not-permitted
但是,我仍然会收到此错误,它表示网络安全策略不允许 CLEARTEXT通信

最佳答案

只需在 list 中的application标签中添加此代码即可:

android:usesCleartextTraffic="true"

这里
<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">

希望对您有所帮助!!

关于java - 网络安全策略不允许与XXX.XXX.XXX.XXX进行CLEARTEXT通信,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59731503/

10-10 02:54