# TokenUSDK

## Introduction

TokenUSDK is an Android SDK designed to provide users with access to multiple libraries through a unified interface. This documentation will guide you through the steps to integrate TokenUSDK into your Android project using a dedicated plugin to manage repository access credentials.

## Integration Guide

### Step 1: Applying Tokeninc Gradle Build Tool Plugin

This plugin allows you to configure your Android projects to consume artifacts from private repositories.

These credentials are asked by the plugin in a Java GUI and this procedure only has to be done once unless credentials are not changed.

If the repository dependencies are managed in project level build.gradle file, enable the build plugin as follows:

Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block), in newer versions of gradle

**Project level build.gradle**

```groovy
plugins {
  id "com.tokeninc.tools.build" version "0.2"
}
```

Using [legacy plugin application](https://docs.gradle.org/current/userguide/plugins.html#sec:old_plugin_application), in older versions of gradle

**Project level build.gradle**

```groovy
buildscript {
  repositories {
    gradlePluginPortal()
  }
  dependencies {
    classpath "com.tokeninc.tools:tokeninc-gradle-plugin:0.2"
  }
}

apply plugin: "com.tokeninc.tools.build"
```

#### Applying Settings Plugin

If the repository dependencies are managed in project level settings.gradle file, enable the build plugin as follows:

Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block), in newer versions of gradle

**Project level settings.gradle**

```groovy
plugins {
  id "com.tokeninc.tools.settings" version "0.2"
}

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    // ..
  }
}

```

#### Java GUI for Settings Plugin, Preferred on Android Studio IDE

On first sync, you will be prompted a window to enter repository consumer credentials:

<figure><img src="/files/db1Tf1UBnrEYWrBOaxsC" alt=""><figcaption></figcaption></figure>

You need to provide the following 3 properties to consume from a Maven Repository

* consume-repo-url-1
* consume-repo-usr-1
* consume-repo-pwd-1

### Step 2: Adding the Dependency

After applying plugin, you should be able to add TokenUSDK dependency as follow:

```groovy
dependencies {
    implementation 'com.tokeninc:TokenUSDK:1.0.4'
}
```

## Usage

TokenUSDK is initialized and accessed through the singleton class `TokenUSDKManager`. Once `TokenUSDKManager` is initialized, it can be used anywhere within your project. However, there are important considerations to ensure proper usage and avoid common pitfalls.

### Initialization

The initialization and destroy process should be performed in the <mark style="color:red;">**onCreate**</mark> and <mark style="color:red;">**onDestroy**</mark> method of the <mark style="color:red;">**Launcher activity**</mark>.  <mark style="color:red;">Same activity context should ne used for bot methods!</mark>

```java
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TokenUSDKManager.getInstance().initUSDK(getBaseContext(), new ITokenUSDKCallback() {
            @Override
            public void onServicesConnected() {
                Log.i(TAG,"TokenUSDK -> onServiceConnected");
                binding.progressCircular.setVisibility(View.GONE);
            }

            @Override
            public void onServiceDisconnected() {
                Log.i(TAG,"TokenUSDK -> onServiceDisconnected");
                binding.progressCircular.setVisibility(View.VISIBLE);
            }
        });
    }
    
    @Override
    protected void onDestroy() {
        TokenUSDKManager.onDestroyUSDK(getBaseContext());
        super.onDestroy();
    }
```

Once initialized, the `TokenUSDKManager` class allows access to any service connection from anywhere in the application.

```java
// example usage of KMSService usage
TokenUSDKManager.getInstance().getKMSService()
```

### Functions

* public PrinterServiceWrapper getPrinterService() : Returns 'PrinterServiceWrapper' for printer functionalities. For further information about Printer Service APIs, please visit: [Printer Service](/token-developer-portal-1/payment-service/system-and-security-services/printer-service.md)
* public RKLServiceWrapper getRKLService() : Returns 'RKLServiceWrapper 'for RKL service functionalities. For further information about RKL service APIs, please visit:  [RKL CA service](/token-developer-portal-1/payment-service/system-and-security-services/rkl-ca-service.md)
* public DeviceInfoWrapper getDeviceInfo() : Returns 'DeviceInfoWrapper 'for DeviceInfo service functionalities. For further information about DeviceInfo service APIs, please visit: [Device Library](/token-developer-portal-1/payment-service/system-and-security-services/device-library.md)
* public KMSWrapper getKMSService(): Returns 'KMSWrapper' for KMS service functionalities. For further information about KMS service APIs, please visit: [KMS Library](/token-developer-portal-1/payment-service/system-and-security-services/kms-library.md)
* public CardServiceWrapper getCardService() : Returns 'CardServiceWrapper' for Card Service functionalities. For further information about Card Service APIs, please visit:  [Card Service](/token-developer-portal-1/payment-service/payment-services/card-service.md)

### Known Issues

#### Java GUI does not appear on first sync

When you apply and sync the project for the first time, you may not see a Java GUI popping up.&#x20;

You might instead come across a warning message from the plugin that says: "Cannot instantiate credentials panel, current graphics environment does not support it!"&#x20;

This is because the previous gradle daemon instance was started in a headless environment, and it must be stopped.&#x20;

Start a terminal on the root directory of the project (e.g. by clicking the tab called Terminal located in the bottom left of Android Studio IDE) and stop the running gradle daemon(s):

&#x20;./gradlew --stop


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.tokeninc.com/token-developer-portal-1/payment-service/system-and-security-services/tokenusdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
