android:usesCleartextTraffic Marshmallow (API-23) 下面的使用方法

How to use android:usesCleartextTraffic below Marshmallow (API-23)

我正在尝试保护 WebView 免受明文流量的影响。如文档中所述。我必须将 android:usesCleartextTraffic 设置为 false 才能实现此目的。但这适用于 API 级别 23 及以上。我的最低 sdk 是 22。如何确保应用程序不会在低于 API 级别 23 的设备 运行 上崩溃或产生任何问题?或者我如何以编程方式在 Manifest.xml 中的 application 标记中设置该属性值?

an article @ Android Developers Blogspot 中所建议:

You don’t have to set minSdkVersion or targetSdkVersion of your app to 23 (Android Marshmallow) to use android:usesCleartextTraffic. On older platforms, this attribute is simply ignored and thus has no effect.

希望这能解决您的问题。

当您在清单中使用 usesCleartextTraffic 时,您会收到以下警告:

Attribute usesCleartextTraffic is only used in API level 23 and higher (current min is 19).

usesCleartextTraffic 的默认值如下:

  • 对于以 API 级别 27 或更低级别为目标的应用是“正确的”。
  • 针对 API 级别 28 或更高级别的应用默认为“false”。

此属性是在 API 级别 23 中添加的。

如果存在 Android 网络安全配置,Android 7.0(API 级别 24)及更高版本将忽略此标志。

https://developer.android.com/guide/topics/manifest/application-element https://android-developers.googleblog.com/2016/04/protecting-against-unintentional.html