zkbnb Android SDK
Android SDK and demo for using zkbnb APIs in your Android app
Install
Using Android studio plugin
Go to Android Studio -> Settings -> Plugins
Search for ZkBNB Android
and install it
SDK will now be ready to use. Proceed to usage section to get started with how to use the sdk.
Using Jitpack
Add Jitpack to your project level build.gradle
file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add zkbnb sdk dependency in your app level build.gradle
file
implementation 'com.github.naman14:zkbnb-android-sdk:0.1'
API Reference
Full SDK API reference docs are available here https://naman14.github.io/zkbnb-android-sdk/api/index.html
Usage
One time initialisation
We first need to initialise the SDK once at app launch. Your app's Application class is the ideal location to do this one time initialisation.
// create a networkConfig to use in sdk
val networkConfig = NetworkConfig(
baseApiUrl = baseUrl, // base api url of the zkbnb api server
isDebug = true // if true, logs network requests to Android logcat
)
// initialise the sdk
ZkBNB.init(
applicationContext,
networkConfig
)
Attach a lifecycle to SDK (Optional)
ZkBNB.attach(lifecycle)
// lifecycle is directly available in activity or fragment
Attaching a lifecycle to sdk is recommended. It allows SDK to automatically cancel API calls if activity is destroyed.
Get data from SDK
Example - Get network status
ZkBNB.getNetworkStatus(object: TaskListener<NetworkStatus> {
override fun onError(e: Throwable) {
Log.d(TAG, e.message)
}
override fun onSuccess(data: NetworkStatus) {
Log.d(TAG, "Network status: ${data.status}, networkId: ${data.networkId}")
}
})
All supported APIs are listed here (All of the zkbnb HTTP APIs are currently supported by the Android SDK)- https://naman14.github.io/zkbnb-android-sdk/api/zkbnb-android-sdk/zk.bnb.android.sdk/-supported-a-p-is/index.html
Demo
A full featured demo is also included in the source code https://github.com/naman14/zkbnb-android-sdk/tree/main/demo
Demo APK can also be directly downloaded from here https://github.com/naman14/zkbnb-android-sdk/releases/download/0.1/zkbnb-android-demo.apk
Plugin
For easier integration of SDK, we have also created an Android Studio plugin to quickly and easily get started with the sdk. Plugin can be installed by searching for ZkBNB Android
on Android Studio plugin marketplace or by downloading and importing plugin directly.
Download plugin