# Development Guide (/global/en/docs/Terminal/NSDK/Development-Guide)

## Preface

This document provides practical guidance for developers building Android applications that interact with NSDK ( Newland Software Development Kit ). It covers integration steps, example code and flowchart to help developers understand and effectively utilize the NSDK APIs.

For detailed API specifications, please refer to the official NSDK API Reference.

## Get Started

### Import NSDK

Import NSDK core package and plugin packages according to your needs:

![](https://docs.newlandnpt.us/assets/_shared/72540fb15dd5/import_nsdk_aar.png)

Make the project compile with aar files in the `libs` folder by adding the following codes to the `build.gradle`:

```groovy
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
```

### Internal Module Development

**Steps to call internal APIs:**

Get the instance of `NSDKModuleManager`.

Init internal modules.

Get the specified device module.

Call the methods of the device module.

Release NSDK resources when app exits.

**Example code:**

```java
NSDKModuleManager moduleManager = NSDKModuleManagerImpl.getInstance();

try {
    nsdkModuleManager.init(context);
} catch(NSDKException e) {
    // Handle the exception.
}

// Get beeper module.
Beeper beeper = (Beeper)moduleManager.getModule(ModuleType.BEEPER);

// Call beeper method.
try {
      // Beep for 3 seconds with frequency 1000hz.
      beeper.beep(1000, 3000);
} catch(NSDKException e) {
      // Handle the exception.
}

// Release NSDK resources.
moduleManager.destroy();
```

### External Module Development

**Steps to call external APIs:**

Connect external PIN pad device via USB/serial port/bluetooth. If using bluetooth, pair the external PIN pad device on the android device first.

Get the instance of the module manager.

Get a default communicator provided by NSDK or set a customized communicator which implements `ExternalCommunicator` to NSDK.

Set UART config if needed

Open external PIN pad device via the communicator (obtained by step 3).

Init external modules after the device is opened successfully.

Get the specified device module.

Call methods of external modules.

Close external PIN pad device via the communicator (obtained by step 2) if no more operations with the external device needed.

Release NSDK resources when app exits.

**Example code:**

```java
ExtNSDKModuleManager moduleManager = ExtNSDKModuleManagerImpl.getInstance();

// Get a default communicator provided by NSDK.
CommunicatorListener communicatorListener = new CommunicatorListener() {
    @Override
    public BluetoothDevice onBluetoothList(ArrayList<BluetoothDevice> bondedDevices) {
        // Choose expected bluetooth device to return.
    }
    @Override
    public void onConnectedStateChange(ExternalCommunicatorState externalCommunicatorState) {
        // Do something when state changes.
    }
};
try {
    communicator = moduleManager.getNSDKCommunicator(context, ExternalCommunicatorType.BLUETOOTH_CLASSIC, communicatorListener);
} catch (NSDKException e) {
    // Handle the exception.
}

// Or new a customized communicator which implements 'ExternalCommunicator' and set it to NSDK.
// CustomizedCommunicator communicator = new CustomizedCommunicator();
// moduleManager.setCommunicator(communicator)

// Set UART config if needed.
// UART3Config config = new UART3Config(BaudRate.BPS115200, DataBits.DATA_BIT_8, ParityBit.NO_CHECK, StopBits.STOP_BIT_ONE);
// moduleManager.setUART3Config(UART3Type.PINPAD_A7, config);

try {
    communicator.open(20000);
} catch (NSDKException e) {
    // Handle the exception.
}

try{
    moduleManager.initExternalModules();
} catch(NSDKException e) {
    // Handle the exception.
}

// Get the specified device module.
ExtBeeper beeper = (ExtBeeper) moduleManager.getModule(ModuleType.EXT_BEEPER);
// Invoke methods of the beeper module.
try {
     beeper.beep(BeeperTone.SUCCESS, 1000);
} catch (NSDKException e) {
     // Handle the exception.
}

try {
    communicator.close(10000);
} catch (NSDKException e) {
    // Handle the exception.
}

// Release NSDK resources when app exits.
moduleManager.destroy();
```