I have foud the following Java code in the Zebra documentation.
https://www.zebra.com/us/en/products/software/barcode-printers/link-os/print-connect.html
Button templatePrint = (Button) findViewById(R.id.templatePrint);
templatePrint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Define a hash map of variable data
// Strings used for keys will be replaced by their corresponding values in your template file's ZPL
HashMap<String, String> variableData = new HashMap<>();
variableData.put("%PRODUCT_NAME%", "Apples");
variableData.put("%MSRP%", "$1.00");
variableData.put("%PCT%", "50");
variableData.put("%FINAL%", "$0.50");
variableData.put("%UPC_CODE%", "12345678");
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.zebra.printconnect",
"com.zebra.printconnect.print.TemplatePrintService"));
intent.putExtra("com.zebra.printconnect.PrintService.TEMPLATE_FILE_NAME", "PriceTagTemplate.zpl");
intent.putExtra("com.zebra.printconnect.PrintService.VARIABLE_DATA", variableData);
intent.putExtra("com.zebra.printconnect.PrintService.RESULT_RECEIVER", buildIPCSafeReceiver(new
ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == 0) { // Result code 0 indicates success
// Handle successful print
} else {
// Handle unsuccessful print
// Error message (null on successful print)
String errorMessage = resultData.getString("com.zebra.printconnect.PrintService.ERROR_MESSAGE");
}
}
}));
startService(intent);
}
});
I'm using it in Delphi 10.3 and I can successfully print, but I can't pass "VARIABLE_DATA", how can I manage it?
procedure TfrmMain.PrintIntent;
var
Intent: JIntent;
NativeComponent : JComponentName;
PackageName, AppName : JString;
begin
Intent := TJIntent.Create;
PackageName := StringToJString('com.zebra.printconnect');
AppName := StringToJString('com.zebra.printconnect.print.TemplatePrintService');
NativeComponent := TJComponentName.JavaClass.init(PackageName, AppName);
Intent.SetComponent(NativeComponent);
Intent.putExtra(StringToJString('com.zebra.printconnect.PrintService.TEMPLATE_FILE_NAME'), StringToJString('PriceTagTemplate.zpl'));
// Intent.putExtra('com.zebra.printconnect.PrintService.VARIABLE_DATA', ???);
MainActivity.startService(Intent);
end;
Thanks to Dave Nottage. It works: