Attribute networkSecurityConfig is only used in API level 24 and higher (current min is 21)
时间: 2024-03-22 09:42:32 浏览: 233
Integrating Ciphertext-policy Attribute-Based Encryption with Identity-Based Ring Signature to Enhance Security and Privacy in Wireless Body Area Networks
If you want to support lower API levels in your Android app, you can create a separate network security configuration file for API level 24 and higher and for lower API levels.
For API level 24 and higher, you can define your network security configuration in the `res/xml/network_security_config.xml` file. For example:
```xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="@raw/my_ca"/>
</trust-anchors>
</base-config>
</network-security-config>
```
For lower API levels, you can define your network security configuration in the `AndroidManifest.xml` file using the `android:usesCleartextTraffic` attribute. For example:
```xml
<application
...
android:usesCleartextTraffic="true">
...
</application>
```
Note that this allows cleartext traffic for the entire app, so it's not recommended for security reasons. Instead, you should define a separate network security configuration for lower API levels if possible.
阅读全文