Android
For the SDK to function, you need to add the required manifest permissions and integrate the SDK.
Manifest permissions
Add the following to the AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />Integration
You can integrate the SDK either via a local Maven repository, or with an aar file.
Integration via local Maven repository
The SDK product package includes a local Maven repository in the maven/ folder. This resolves transitive dependencies automatically and enables inline KDoc in Android Studio.
Copy the maven/ folder from the SDK package into your app's directory (i.e. together with build.gradle), then add the following to build.gradle:
repositories {
maven { url uri("${rootDir}/app/maven") }
}
dependencies {
implementation 'com.onespan:sdk_network_security_android:+'
}Integration via aar file (flat dependency)
Place the NetworkSecuritySDK.aar file from the SDK package into your app’s aars/ folder, then add the following to build.gradle:
repositories {
flatDir { dirs 'aars' }
}
dependencies {
implementation(name: 'NetworkSecuritySDK', ext: 'aar')
implementation 'androidx.core:core-ktx:1.15.0'
}Usage
Follow these steps:
Create an instance.
val networkSecurity = NetworkSecurity.create(applicationContext)Retrieve the current network information (one-shot).
networkSecurity.getCurrentNetworkInfo { info -> println("Type: ${info.type}") println("Secure: ${info.isSecure}") println("VPN: ${info.vpnConnectionStatus}") println("Wi-Fi: ${info.wifiInfo?.ssid}") println("Cellular: ${info.cellularInfo?.carrierName}") }Monitor for network changes.
// Start listening networkSecurity.registerNetworkChangeListener { info -> println("Network changed: ${info.type}") } // Stop listening (e.g. in onDestroy) networkSecurity.unregisterNetworkChangeListener()Get user-installed CA certificates.
try { val certs = networkSecurity.getUserInstalledCertificates() certs.forEach { cert -> println("Alias: ${cert.alias}, Subject: ${cert.certificate.subjectDN}") } } catch (e: NetworkSecuritySDKException) { println("Error ${e.errorCode}") }Get SDK version.
println(networkSecurity.getVersion()) // or statically: println(NetworkSecurity.VERSION)
Error handling
All SDK methods can return errors. When NetworkSecuritySDKException is thrown, determine the cause by checking the exception’s errorCode against NetworkSecuritySDKErrorCodes:
Code | Message | Meaning |
|---|---|---|
-2100 |
| Unexpected internal error |
-2101 |
| Context was null |
-2102 |
| Required permission not granted |
-2103 |
| Device is offline |
-2104 |
| Could not read certificate store |
iOS
To use the Network Security SDK in your iOS project
Link NetworkSecuritySDK.xcframework from the OneSpan Mobile Security Suite package to your Xcode project (linked framework and libraries).
Add the location permission for the key: Privacy - Location When In Use Usage Description
Add the Access Wi-Fi Information capability.
You are now ready to use the Network Security SDK.
API reference documentation and sample applications
To learn more about the public APIs and their functions, exceptions, and error codes, refer to the technical documentation that is included in the product package for each SDK and each platform. In the product package, you can also find the sample applications provided for each platform to see examples of how the SDKs can be used.
These sample apps are intended only to demonstrate basic scenarios and SDK usage. They are not designed to be copied directly into production projects!