I have a big problem for a long time - I am looking for a solution everywhere, but after really many hours of testing I can not find a sensible solution.
I have a JAR library for the Zebra printer and a PAS file for it (
http://aboutit.pl/MobilePrinter.zip). I need a piece of code in Delphi that will handle a callback (JHandle) single procedure from a JAR library.
Something like this:
TPrintCallback = class (TJavaLocal, JHandler_Callback)
function handleMessage (msg: JMessage): Boolean; cdecl;
end;
TfrmMain = class (TForm)
[..]
private
FCallback: TPrintCallback;
FHandler: JHandler;
end;
[...]
procedure TfrmMain.FormCreate (Sender: TObject);
begin
FCallback: = TPrintCallback.Create;
FHandler: = TJHandler.JavaClass.init (FCallback);
FPrinter1: = TJMobilePrinter.JavaClass.Init (TAndroidHelper.Context,FHandler, TJLooper.JavaClass.getMainLooper);
[...]
end;
function TPrintCallback.handleMessage (msg: JMessage): Boolean;
begin
Result: = True;
//Only example
ShowMessage (msg.what.ToString + '' + msg.arg1.ToString);
end;
I would like the handleMessage function to receive messages, e.g. about the printer's connection. Of course, the printer object can do it, but messages do not reach the Delphi application.
I also tried the RegisterNatives method, but also without success
procedure RegisterN;
var
PEnv: PJNIEnv;
ReceiverClass: JNIClass;
NativeMethod: JNINativeMethod;
begin
try
PEnv := TJNIResolver.GetJNIEnv;
ReceiverClass := TJNIResolver.GetJavaClassID('com/zebra/printer/service/PrinterHandler');
NativeMethod.Name := 'handleMessage';
NativeMethod.Signature := '(Landroid/os/Message;)V';
NativeMethod.FnPtr := @handleMessage;
PEnv^.RegisterNatives(PEnv, ReceiverClass, @NativeMethod, 1);
PEnv^.DeleteLocalRef(PEnv, ReceiverClass);
except
on E: Exception do
ShowMessage(E.Message);
end;
end;
I am ready to pay for any hint, where to look for a solution to this problem - I am in desperation.

Connect with Us