It appears you have already asked a similar question, here: https://stackoverflow.com/questions/65345853/is-it-possible-to-write-the-following-java-program-in-delphi
The principal for your present issue is identical, i.e. if OnPrintListener is a class, then you. cannot do it in Delphi. If it's an interface (which, given your other question, it's likely), then you already have an example of how to implement a Java interface, in the StackOverflow answer. A possible example for this case:
uses
Androidapi.JNIBridge, Androidapi.JNI.JavaTypes, Androidapi.Helpers;
type
JOnPrintListener = interface;
JOnPrintListenerClass = interface(IJavaClass)
['{076904DD-77D9-497D-BA21-992A9B8FED3E}']
end;
[JavaSignature('com.nexgo.oaf.apiv3.device.printer.OnPrintListener')]
JOnPrintListener = interface(IJavaInstance)
['{F688775D-067F-4521-A045-9106599F4C4A}']
procedure onPrintResult(retCode: Integer); cdecl;
// *** NOTE *** There may be other methods for this interface
end;
TJOnPrintListener = class(TJavaGenericImport<JOnPrintListenerClass, JOnPrintListener>) end;
TRunnable = class(TJavaLocal, JRunnable)
private
FCallback: TProc;
public
{ JRunnable }
procedure run; cdecl;
public
constructor Create(const ACallback: TProc);
end;
TPrintListener = class(TJavaLocal, JOnPrintListener)
private
FRetCode: Integer;
FRunnable: JRunnable;
procedure DoRun;
public
{ JOnPrintListener }
procedure onPrintResult(retCode: Integer); cdecl;
public
constructor Create;
end;
{ TRunnable }
constructor TRunnable.Create(const ACallback: TProc);
begin
inherited Create;
FCallback := ACallback;
end;
procedure TRunnable.run;
begin
FCallback;
end;
{ TPrintListener }
constructor TPrintListener.Create;
begin
inherited;
FRunnable := TRunnable.Create(DoRun);
end;
procedure TPrintListener.DoRun;
begin
// Do the toast thing here, using FRetCode
end;
procedure TPrintListener.onPrintResult(retCode: Integer);
begin
FRetCode := retCode;
TAndroidHelper.Activity.runOnUiThread(FRunnable);
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
// Assuming FPrintListener is defined as: FPrintListener: JOnPrintListener
FPrintListener := TPrintListener.Create;
// Assuming you have created an instance of Printer (imported as JPrinter) called FPrinter
FPrinter.startPrint(False, FPrintListener);
end;
Note all of the assumptions being made - the biggest one being that OnPrintListener is an interface. Also I don't have the .jar, nor the printer, so of course it is untested