Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: FireMonkey Android - handle callback message (JHandle) of JAR object


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Feb 5, 2018 7:13 PM Last Post By: Eli M
Karol Nawrot

Posts: 1
Registered: 2/24/17
FireMonkey Android - handle callback message (JHandle) of JAR object  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 30, 2018 2:28 PM
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. ;-)
Eli M

Posts: 1,346
Registered: 11/9/13
Re: FireMonkey Android - handle callback message (JHandle) of JAR object  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 5, 2018 7:13 PM   in response to: Karol Nawrot in response to: Karol Nawrot
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02