Enabling Connection Keep-Alive
The Connection Keep-Alive feature gives you the option to keep the connection to the card reader established after the first transaction has been completed. Subsequent transactions will use the already connected reader, allowing your merchants to take card payments even faster.
This feature is designed for setups in which the card reader is connected to a power source most of the time. If your merchant wants to run the card reader mostly on battery power, you need to implement some basic power management using the explicit disconnect method described below.
Enabling Connection Keep-Alive
Set
keepAlive(...)
to
true
in the
AccessoryParameters
you supply:
AccessoryParameters params = new AccessoryParameters.Builder(AccessoryFamily.MIURA_MPI).
bluetooth().
keepAlive(true).
build();
After the first transaction has been completed, the card reader will remain connected and display the idle screen. If you then use the same
AccessoryParameters
for subsequent transactions, the already connected reader will be used.
You can customize the idle screen text shown on the reader through the
AccessoryParameters
as well.
Each connection to the reader is tied to an instance of the
TransactionProvider
. In order to use the Connection Keep-Alive feature, you have to create a single instance of
TransactionProvider
once during application start up and use that instance for interacting with the SDK throughout the application.
Disconnecting from the Card Reader
Through the
AccessoryModule
in the
TransactionProvider
you can disconnect from a connected reader explicitly. This is especially useful when you are running the card reader on battery power and want to disconnect after a certain idle time or situation such as merchants logging out of the POS system.
AccessoryModule accessoryModule = transactionProvider.getAccessoryModule();
Accessory accessory = accessoryModule.getConnectedAccessories().get(0);
accessoryModule.disconnectFromAccessory(accessory, new AccessoryDisconnectListener2() {
@Override
public void onStatusChanged(AccessoryProcess process, Accessory model, AccessoryProcessDetails processDetails) {
// status updates on the ongoing process
}
@Override
public void onCompleted(AccessoryProcess process, Accessory model, AccessoryProcessDetails processDetails) {
// disconnection finished, check the process details for the outcome
if (processDetais.getState() == AccessoryProcessDetails.FAILED) {
Log.d(TAG, "disconnect failed: " + processDetais.getError());
} else {
Log.d(TAG, "disconnect success");
}
}
});