NetworkSecurityConfig
public
final
class
NetworkSecurityConfig
extends Object
| java.lang.Object | |
| ↳ | android.security.net.config.NetworkSecurityConfig |
The security configuration to use when performing network communications.
A NetworkSecurityConfig can specify security requirements for all network
communications, or for communications with a specific domain or localhost connections.
See also:
Summary
Nested classes | |
|---|---|
class |
NetworkSecurityConfig.Builder
Builder for creating |
Public methods | |
|---|---|
static
NetworkSecurityConfig
|
createBaseConfig(Context context)
Returns a base |
static
NetworkSecurityConfig
|
createLocalhostConfig()
Returns a |
int
|
getDomainEncryptionMode()
|
boolean
|
isCertificateTransparencyVerificationRequired()
|
boolean
|
isCleartextTrafficPermitted()
|
Inherited methods | |
|---|---|
Public methods
createBaseConfig
public static NetworkSecurityConfig createBaseConfig (Context context)
Returns a base NetworkSecurityConfig using the provided app's defaults.
An app default configuration has the following properties:
- If the application targets API level 27 (Android O MR1) or lower, cleartext traffic is allowed by default.
- Cleartext traffic is not permitted for ephemeral apps.
- No certificate pinning is used.
- The system certificate store is trusted for connections.
- If the application targets API level 23 (Android M) or lower than the user certificate store is trusted by default as well for non-privileged applications.
- Privileged applications do not trust the user certificate store on Android P and higher.
| Parameters | |
|---|---|
context |
Context: of the application. Must not be null. |
| Returns | |
|---|---|
NetworkSecurityConfig |
the application NetworkSecurityConfig, or null if the config cannot
be found. |
createLocalhostConfig
public static NetworkSecurityConfig createLocalhostConfig ()
Returns a NetworkSecurityConfig for localhost.
The localhost configuration has the following properties:
- Cleartext traffic is permitted.
- Certificate Transparency is disabled.
| Returns | |
|---|---|
NetworkSecurityConfig |
the NetworkSecurityConfig.
This value cannot be null. |
getDomainEncryptionMode
public int getDomainEncryptionMode ()
| Returns | |
|---|---|
int |
the domain encryption mode. For possible values see NetworkSecurityPolicy.getDomainEncryptionMode(String).
Value is one of the following: |
isCertificateTransparencyVerificationRequired
public boolean isCertificateTransparencyVerificationRequired ()
| Returns | |
|---|---|
boolean |
true if Certificate Transparency is required for this NetworkSecurityConfig. |
isCleartextTrafficPermitted
public boolean isCleartextTrafficPermitted ()
| Returns | |
|---|---|
boolean |
true if cleartext traffic is permitted for this NetworkSecurityConfig. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-07-20 UTC.