Integračná dokumentácia Help

ANDROID via LDM

For supporting simple and quick integration, a basic example is provided on how to connect to the service and execute a simple Pegas Script.

The Android Studio project can be downloaded from:

Link

The project contains a library that includes all the necessary functions for script processing in the folder app/libs.

Project settings

In the AndroidManifest.xml, the following modifications need to be made:

  1. Add permission:

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  2. From Android 11 onwards, it is necessary to further define:

    <queries> <package android:name="sk.epopay.pos.printer" /> <package android:name="sk.singularisdev.androidekasa.client" /> </queries>
  3. Into build.gradle:

    implementation (files("libs/LdmClient-release.aar"))

Example of AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.LdmClientExample" tools:targetApi="31"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <queries> <package android:name="sk.epopay.pos.printer" /> <package android:name="sk.singularisdev.androidekasa.client" /> </queries> </manifest>

Initialization of the connection with LDM

Attention: It is necessary to execute methods for connection and script execution outside the UI thread! Calling them on the UI thread will cause it to block. This is handled directly in the library, and a UiThreadViolationException will be thrown.

private LdmClient ldmClient; // ... @Override protected void onCreate(Bundle savedInstanceState) { // ... ldmClient = new LdmClient(getApplicationContext()); // ... }

Connection to the LDM service

private class ConnectAsyncTask extends AsyncTask<Void, Void, String> { protected String doInBackground(Void... params) { try { boolean connected = ldmClient.connect(); return connected ? "connected" : "not connected - call again"; } catch (UiThreadViolationException e) { return "connect called from UI thread - please use non-ui thread!"; } catch (ServiceDoesNotExistException e) { return "LDM service does not exists on this device!"; } } @Override protected void onPostExecute(String message) { Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show(); if (message.equals( "connected")) { testScriptButton.setVisibility(View.VISIBLE); reconnectButton.setVisibility(View.GONE); } else { testScriptButton.setVisibility(View.GONE); reconnectButton.setVisibility(View.VISIBLE); } } }

Handling error exceptions

Exception

Solution

UiThreadViolationException

Utilize a separate thread for connecting to the service

ServiceDoesNotExistException

Check for the existence of the required application - eKasaClient or EpoPay POS Service

Execution of the script

private class TestSciptAsyncTask extends AsyncTask<Void, Void, String> { @Override protected String doInBackground(Void... params) { try { String result = ldmClient.processFmScript("gettVariable:B51\r\n"); return result; } catch (LdmCommunicationException e) { e.printStackTrace(); return "LdmCommunicationException"; } catch (ScriptProcessingException e) { e.printStackTrace(); return "ScriptProcessingException"; } catch (ScriptParsingException e) { e.printStackTrace(); return "ScriptParsingException - unknown command, wrong format etc."; } catch (LdmIsNotInitialized e) { e.printStackTrace(); return "LDM is not initialized"; } catch (UiThreadViolationException e) { return "connect called from UI thread - please use non-ui thread!"; } catch (ClientIsNotInitializedException e) { return "LDM client is not initialized - call connect again"; } catch (LdmException e) { e.printStackTrace(); return "internal error - log this exception for support"; } } @Override protected void onPostExecute(String message) { Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show(); } }

Exception handling

Exception

Solution

LdmCommunicationException

Error encountered during communication with the service, call disconnect and reconnect. If the error persists, contact support.

ScriptProcessingException

The service does not exist, please verify the existence of the required application - eKasaClient or EpoPay POS Service.

ScriptParsingException

Error encountered while processing the script, unknown command, incorrect parameter format, etc.

LdmIsNotInitialized

The LDM service is not initialized. It is necessary to initialize it either via the GUI or EpoPay Launcher OnBoarding.

UiThreadViolationException

Utilize a separate thread for connecting to the service.

ClientIsNotInitializedException

The service is not connected. You need to call the method connect.

LdmException

Internal error, which should not occur, log the exception and contact support.

Last modified: 23 februára 2026