Huawei Android SDK
Try our SDK in your Android application
1. Integrate dependencies
To integrate our SDK into your application edit your build.gradle:
Add this block to the root section:
allprojects {
repositories {
//...
maven {
url "https://jitpack.io"
}
}
}
Add this block to the dependencies section:
implementation 'com.github.FendAiCorp.fendvpn-android:sdk:<VERSION>'
2. Configurate SDK
To start using the SDK, you need to create a WireSdk instance. Initialize FendSDK with a WireConfig:
val sdk = WireSdk.provide(
WireConfig("backend url", "project id", "app version")
)
Value
Description
backend URL
Base URL for the API calls (login, fetching locations, etc.)
project id
A unique identifier of the project
app version
The application version for analytics purposes
3. Use API
After SDK initialization you need to authenticate the user on the backend and acquire the list of available locations to connect.
3.1 Authentication
sdk.api().login(WireAuth.AuthAnonymous).fold(
onSuccess = {
//success
},
onFailure = {
//error
}
)
sdk.api().logout() // logout the user
sdk.api().isLoggedIn() // check if user is logged in
3.2 Available locations
sdk.api().locations().fold(
onSuccess = { locations ->
// select location to connect to
},
onFailure = {
// error
}
)
4. Manage VPN
After getting a virtual location configuration, you are ready to start a VPN session.
4.1 Start / Stop
val location: VirtualLocation = //use location fetched
// on the previous step
sdk.vpn().start(SessionConfig(location)).fold(onSuccess = {
// connected
}, onFailure = {
// connection error
})
sdk.vpn().stop() // to stop vpn session
4.2 Statistics
An active VPN connection provides statistics on the amount of traffic, connection start time, and the chosen VPN server IP.
val stats = sdk.vpn().stats()
stats.fold(
onSuccess = {
// update traffic data
},
onFailure = {
// error
}
)
4.3 State
The SDK can provide information on the current VPN tunnel state.
sdk.vpn().state().collect { state->
// state updated
}
Value
Description
VpnState.IDLE
No active VPN connection exists
VpnState.CONNECTING
Establishing a VPN connection right now
VpnState.CONNECTED
A VPN connection is established and active
VpnState.ERROR
A VPN connection process has failed
Last updated
Was this helpful?