【问题标题】:CLEARTEXT communication - Android明文通信 - Android
【发布时间】:2020-07-17 07:21:13
【问题描述】:

我的 android 项目面临这个 Cleartext 问题。
我几乎用过所有的 stackoverflow 答案、各种博客等,但 android 不允许我连接到服务器。 这是一个非常小的应用程序,将被 20+ ppl 用于每天在本地网络上上传一些数据。所以 HTTPS 对我来说是一个禁区。

清单版本-1

    <application
        android:usesCleartextTraffic="true"
        tools:ignore="GoogleAppIndexingWarning"
        android:theme="@style/AppTheme">
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

清单版本 2

<application
        android:allowBackup="true"
        android:usesCleartextTraffic="true" <!-- With and Without -->
        android:networkSecurityConfig="@xml/network_security_config"
        tools:ignore="GoogleAppIndexingWarning"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Network_Security_Config

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain> <!-- Debug port -->
        <domain includeSubdomains="true">192.168.0.104</domain>
    </domain-config>
</network-security-config>

我还尝试创建一个 minSdk 21 和目标 sdk 24 项目,但使用 HTTPUrlConnection 时遇到了同样的问题
请指导。谢谢。

我检查过的一些链接
Retrofit CLEARTEXT communication not enabled for client
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?
https://developer.android.com/about/versions/pie/android-9.0-changes-all
Internet permission not working in oreo and pie

【问题讨论】:

  • 你是否在应用标签内添加了清单行?
  • 是的,它在应用程序之间。检查更新的问题。

标签: android httpurlconnection cleartext


【解决方案1】:

您是否曾尝试将其添加到清单应用程序中,

    android:usesCleartextTraffic="true"

而不是

android:networkSecurityConfig="@xml/network_security_config"

【讨论】:

  • 是的。我已经将它与 android:networkSecurityConfig="@xml/network_security_config" 结合使用,也没有它。
  • 不,我的意思是,没有 android:networkSecurityConfig="@xml/network_security_config",我之所以这么问,是因为我在它适用于我的情况之前就使用过它。我没有将它与 "android:networkSecurityConfig" 一起使用。所以,也许将它们结合起来并不是一个好主意。
  • 是的。也单独使用了所有组合。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-11
  • 2022-01-17
  • 1970-01-01
相关资源
最近更新 更多