Integrate oneconnect SDK for Android

OneConnect SDK Android Library

OneConnect SDK is an Android library that provides easy access to OneConnect API, allowing you to retrieve server information for VPN services. You can use this library to fetch both free and premium servers for your VPN application.


To use this library, you should add jitpack repository.

Add this to root build.gradle

allprojects {
    repositories {
        maven {
            url ""

Add this in Androidmainfest.xml

    android:theme="@style/blinkt.dialog" />
        <action android:name="" />

To use OneConnect SDK in your Android project, add the following dependency to your app-level build.gradle file:

implementation 'com.github.oneconnectapi:OneConnectLib:v1.1.0'


Here's how you can use OneConnectLib to fetch server information for your VPN application:

Thread thread = new Thread(new Runnable() {
    public void run() {
        try {
            OneConnect oneConnect = new OneConnect();
            String apiKey = "nwc6VcLemvnZQxaAgmMGMLtLMxmNT7tud.X.WXBqFbXjWogVWk"; //Sample API key
            oneConnect.initialize(this, apiKey);
            try {
                //Returns a Json string containing all the server details and credentials
                Constants.FREE_SERVERS = oneConnect.fetch(true);
                Constants.PREMIUM_SERVERS = oneConnect.fetch(false);
            } catch (IOException e) {
        } catch (Exception e) {


In the code snippet above:

  • Create a new thread to perform network operations asynchronously.

  • Initialize the OneConnect instance with your API key.

  • Use oneConnect.fetch(true) to retrieve free servers and oneConnect.fetch(false) to retrieve premium servers.

Connect VPN

OpenVpnApi.startVpn(this, config, countryName, userName, passWord);


  • this - The activity context

  • config - configuration file

  • countryName - Text to be displayed in the notification

  • userName - handle by SDK itself

  • passWord - handle by SDK itself

Disconnect VPN

OpenVPNThread vpnThread = new OpenVPNThread();

try {
} catch (Exception e) {

Parsing JSON Response

Once you have fetched server information, you can parse the JSON response to obtain the server details. Here's an example of how to convert the JSON response into an ArrayList of Countries objects:

ArrayList<Countries> servers = new ArrayList<>();

try {
    JSONArray jsonArray = new JSONArray(Constants.FREE_SERVERS);
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject object = jsonArray.getJSONObject(i);
        servers.add(new Countries(
} catch (JSONException e) {

Make sure to replace Countries with the appropriate data model in your project.

Ready demo project

Here we have ready demo project , you can frog from GitHub and use


This SDK Project is Created By OneConnect Team.

This Project Content OneConnect Library

For Use, the SDK Required OneConnect API Key,

Visit on this Website and Create Account and get the Key.

Once You have the OneConnect API Key, Then You have Put inside

You will Get the Key inside API Tab After that, You need to Put Your App Package Name Inside OneConnect API Tab.

You have to Put inside Please See Screenshot

# This Project Content AdMob & Facebook Ads those developers want to Add Another Ads SDK they need to follow the Exiting Method of Ads SDK and Also Have IAP Subscription.

And Need to Put Your Google-Services.JSON file inside Project, You will get from Firebase.

Note :- Any Developer, those who want to Use or Sell for end Client

they need to make the sufficient Changes in the Original Demo Project.

Just Smile after get the Project..... (^_^)

Last updated