Smart Terminal Management with myPOS Smart SDK
This section covers advanced terminal management features for myPOS Smart devices, including SAM module operations, receipt printing, and custom printing logic. To use these features, ensure your terminal is running myPOS OS version 0.0.8 or later. You can check this version under Terminal App > Debug Mode > About.
SAM Module Operations
Manage the built-in SAM 1 and SAM 2 modules with the following sample logic:
//Build SAM module operation
private static final int SAM_SLOT_1 = 1;
private static final int SAM_SLOT_2 = 2;
private void startSAMTest() {
final Context context = this;
Thread r = new Thread(new Runnable(){
@Override
public void run() {
try {
int slotNumber = SAM_SLOT_1;
int timeoutMs = 1000;
boolean hasCard;
byte[] resp;
byte[] cmd = new byte[] {(byte)0x00,(byte)0xA4,(byte)0x00,(byte)0x00,(byte)0x02, (byte) 0x3f, (byte) 0x00}; // SELECT command for file 0x3F00 (GSM card master file)
hasCard = SAMCard.detect(context, slotNumber, timeoutMs);
if (!hasCard) {
showToast("No SAM card detected in slot " + slotNumber);
return;
}
showToast("SAM card detected in slot " + slotNumber + ". Initializing");
resp = SAMCard.open(context, slotNumber, timeoutMs);
showToast("Initializing SAM successful. Sending command");
resp = SAMCard.isoCommand(context, slotNumber, timeoutMs, cmd);
showToast("Response to SAM command received. Closing SAM");
SAMCard.close(context, slotNumber, timeoutMs);
showToast("SAM module closed");
} catch (Exception e) {
e.printStackTrace();
showToast(e.getMessage());
}
}
});
r.start();
}
public void showToast(final String toast)
{
runOnUiThread(new Runnable() {
public void run()
{
Toast.makeText(MainActivity.this, toast, Toast.LENGTH_SHORT).show();
}
});
}
Print Last Transaction Receipt
1. Send the Print Broadcast
Intent intent = new Intent(MyPOSUtil.PRINT_LAST_RECEIPT_BROADCAST);
intent.putExtra("print_customer_receipt", true);
sendBroadcast(intent);
2. Handle the Result
public class PrinterResultBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean printing_started = intent.getBooleanExtra("printing_started", false);
int printer_status = intent.getIntExtra("printer_status", PrinterStatus.PRINTER_STATUS_UNKNOWN_ERROR);
// If the printing has actually started, handle the status
if (printing_started) {
// Handle success and errors
if (printer_status == PrinterStatus.PRINTER_STATUS_SUCCESS) {
Toast.makeText(context, "Printing successful!", Toast.LENGTH_SHORT).show();
// Printing is successful
} else if (printer_status == PrinterStatus.PRINTER_STATUS_OUT_OF_PAPER) {
// Show "missing paper" dialog
Toast.makeText(context, "No paper in the printer", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, String.format("Some error occurred while printing. Status: %d", printer_status), Toast.LENGTH_SHORT).show();
}
// etc.
} else {
// Some other error occurred. Maybe there's no transaction data (when printing last transaction receipt).
Toast.makeText(context, String.format("Error occurred while printing. Status: %d", printer_status), Toast.LENGTH_SHORT).show();
}
}
}
Print a Custom Receipt
1. Prepare and Send the Broadcast
To send a custom receipt, you can use a list of PrinterCommand objects and serialize them with Gso:
List<PrinterCommand> commands = new ArrayList<>();
commands.add(new PrinterCommand(PrinterCommand.CommandType.TEXT, "Normal row 1\n"));
commands.add(new PrinterCommand(PrinterCommand.CommandType.TEXT, "Double height\n\n\n", false, true));
commands.add(new PrinterCommand(PrinterCommand.CommandType.FOOTER));
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sample);
commands.add(new PrinterCommand(PrinterCommand.CommandType.IMAGE, bitmap));
Gson gson = new Gson();
String json = gson.toJson(commands);
Intent intent = new Intent(MyPOSUtil.PRINT_BROADCAST);
intent.putExtra("commands", json);
MyPOSAPI.sendExplicitBroadcast(context, intent);
You can use HEADER, LOGO, TEXT, FOOTER, and IMAGE types in PrinterCommand.
2. Handle the Printing Result
Use the same PrinterResultBroadcastReceiver (as above) to handle the result from com.mypos.broadcast.PRINTING_DONE.
Tip: Always handle printer errors gracefully—especially for issues like missing paper or connection failures. When printing receipts, ensure your app checks the terminal’s printer capabilities first.