Initializing the Manager
This guide explains how to instantiate the PeripheralsManager class. This class serves as the central controller for all hardware operations, including printing, scanning, and device configuration.
The PeripheralsManager handles the low-level connection to the terminal’s hardware. You do not need to manually open or close connections; the manager handles this automatically upon instantiation.
Step 1: Create the Manager Instance
To start using the library, you must create an instance of PeripheralsManager. The constructor requires the current application or activity Context.
import com.redsys.peripherals.PeripheralsManager; // Example package import
// Inside your Activity or Service
PeripheralsManager manager = new PeripheralsManager(this);Once initialized, the connection to the terminal is established automatically.
Best Practices
Use a Singleton Pattern
It is highly recommended to maintain a single instance of PeripheralsManager throughout your application’s lifecycle. Creating multiple instances may lead to resource conflicts or connection stability issues.
Recommended Approach:
Initialize the manager once (e.g., in your Application class or using a dependency injection framework like Dagger/Hilt) and pass this reference to the activities or fragments that need it.
Example: Application-Level Initialization
public class MyApplication extends Application {
private PeripheralsManager peripheralsManager;
@Override
public void onCreate() {
super.onCreate();
// Initialize once with Application context
peripheralsManager = new PeripheralsManager(this);
}
public PeripheralsManager getPeripheralsManager() {
return peripheralsManager;
}
}Next Steps
Now that you have an initialized manager, you can proceed to: