Jump to content
bcvs

Android: Use a class from a .jar-File

Recommended Posts

Hi,
 I have to use an .jar file in my Android App. I've already created this bridge file and added the .jar as library as explained here:
inlink.gifhttp://docwiki.embarcadero.com/RADSt...o_Android_Apps

So far everythis is OK. Now I'm about to use the classes in my App. To start and to get into it I wand to call the function isNfcEnabled. The corresponding class looks like this in the bridge file:


 

  JCardlinkClass = interface(JICardlinkCallbackClass)
    ['{62BD9E24-88F0-4FD3-BD57-65479E39241E}']
    {class} function _GetINSTANCE: JCardlink; cdecl;
    {class} function getDebug: Boolean; cdecl;
    {class} function getLogLevel: JLogLevel; cdecl;
    {class} function getSmsHack: Boolean; cdecl;
    {class} function getState: JCardlinkState; cdecl;
    {class} procedure initialize(string_: JString; iCardlinkCallback: JICardlinkCallback; string_1: JString; string_2: JString); cdecl;
    {class} function isNfcEnabled(context: JContext): Boolean; cdecl;
    {class} function isNfcHardwareAvailable(context: JContext): Boolean; cdecl;
    {class} procedure requestSmsToken(string_: JString; string_1: JString; string_2: JString; string_3: JString); cdecl;
    {class} procedure setDebug(b: Boolean); cdecl;
    {class} procedure setLogLevel(logLevel: JLogLevel); cdecl;
    {class} procedure setSmsHack(b: Boolean); cdecl;
    {class} procedure shutdown; cdecl;
    {class} procedure startScan(string_: JString; activity: JActivity); cdecl;
    {class} procedure verifySmsToken(string_: JString); cdecl;
    {class} property INSTANCE: JCardlink read _GetINSTANCE;
  end;

  [JavaSignature('de/...../Cardlink')]
  JCardlink = interface(JICardlinkCallback)
    ['{46B08D27-AA20-4A0D-971E-7405E46E0787}']
    procedure onError(cardlinkError: JCardlinkError; string_: JString; cardlinkAction: JCardlinkAction); cdecl;
    procedure onPrescriptionBundles(list: JList); cdecl;
    procedure onPrescriptionTokens(string_: JString); cdecl;
    procedure onProgressUpdate(i: Integer); cdecl;
    procedure onStateChanged(cardlinkState: JCardlinkState); cdecl;
  end;
  TJCardlink = class(TJavaGenericImport<JCardlinkClass, JCardlink>) end;  

I think I have to create an instance of JCardlink first.

 

What I tried:

 

var CardLink: TJCardlink;

CardLink:=TJCardlink.JavaClass.INSTANCE; // <-- Incompatible Types TJCardlink und JCardlink
CardLink.JavaClass.isNfcEnabled(context); 

 

var CardLink: TJCardlink;

CardLink:=TJCardlink.Create; // <-- Incompatible Types TJCardlink und JCardlink
CardLink.JavaClass.isNfcEnabled(context);
var CardLink: JCardlink;

CardLink:=TJCardlink.JavaClass.INSTANCE;
CardLink.JavaClass.isNfcEnabled(context); // <-- unknown identifier JavaClass
CardLink.isNfcEnabled(context); // <-- unknown identifier isNfcEnabled

It seems that I can only create an instance of JCardlink. But isNfcEnabled is a member of JCardlinkClass or TJCardlink.JavaClass. How can I get this together?

 

 

 

 

Share this post


Link to post
3 hours ago, bcvs said:

CardLink.JavaClass.isNfcEnabled(context);

This should be:

if TJCardLink.JavaClass.isNfcEnabled(context) then
  // Take whatever action needed if NFC is enabled

 

Share this post


Link to post

Thank you, that works.

 

I was wrong when I thought, that I had to create in instance on TJCardlink as in this case it is a singleton.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×