Android SDK Integration Guide

To help you integrate the myPOS Android SDK into your mobile application, follow the steps below. You can also refer to our sample app on GitHub for a complete working example.

Installation

Add the Maven repository to your build.gradle:

Code Example

Java
allprojects {
    repositories {
        mavenCentral()
  }
}

Add the SDK dependency to your app module:

Code Example

Java
implementation 'com.mypos:slavesdk:2.1.6'

Initialization

Initialize the myPOS components in your application class:

Code Example

Java
public class SampleApplication extends Application {

private POSHandler  mPOSHandler;

@Override
public void onCreate() {
	super.onCreate();
	POSHandler.setCurrency(Currency.EUR);
 	mPOSHandler = POSHandler.getInstance();
}

Optional Settings

Receipt Configuration

Set the default receipt behavior:

Code Example

Java
POSHandler.setDefaultReceiptConfig(POSHandler.RECEIPT_PRINT_ONLY_MERCHANT_COPY);

To remove the default config:

Code Example

Java
POSHandler.clearDefaultReceiptConfig();

Language Setting
Set the receipt language (default is English):

Code Example

Java
POSHandler.setLanguage(Language.GERMAN);

Check Terminal Activity
Check if the terminal is busy:

Code Example

Java
POSHandler.getInstance().isTerminalBusy();

Connect to Terminal

Select connection type:

Code Example

Java
POSHandler.setConnectionType(ConnectionType.BLUETOOTH);
POSHandler.getInstance().connectDevice(context);

Check permissions:

Code Example

Java
if (POSHandler.getInstance().checkPermissions(context)) {
    // continue...
} else {
    // permissions request is sent...
}

Handle permission results:

Code Example

Java
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
   if (requestCode == POSHandler.PERMISSIONS_REQUEST_CODE) {
       // check permissions result...
   }
}

Bluetooth Low Energy (Go 2 Terminals)

To skip manual pairing, use a BroadcastReceiver:

Code Example

Java
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
registerReceiver(broadCastReceiver, intentFilter);

Code Example

Java
private BroadcastReceiver broadCastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if(BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action))
        {
            BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            int blPin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 123456);
            bluetoothDevice.setPin(blPin);
            bluetoothDevice.createBond();
        }
    }
};

Attach Listeners

Connection Listener

Code Example

Java
mPOSHandler.setConnectionListener(new ConnectionListener() {
    @Override
    public void onConnected(final BluetoothDevice device) {
        // handle connected event here
    }
});

POS Ready Listener

Code Example

Java
mPOSHandler.setPOSReadyListener(new POSReadyListener() {
    @Override
    public void onPOSReady() {
        // now you can start a transaction
    }
});

Send E-Receipt

To send an email or SMS receipt, use the following configuration and listener:

Code Example

Java
POSHandler.getInstance().setPOSCredentialsListener(new POSCredentialsListener() {
    @Override
    public void askForCredentials(final CredentialsListener listener) {
	listener.onCredentialsSet("email@example.com"); // instead of email you can pass a phone number
    }
});

Pro Tip: Always monitor connection and terminal readiness before initiating transactions, and wrap all listener logic with proper error handling for a smoother user experience.