* * *

Author Topic: Android JNI Bridge  (Read 865 times)

AliZairov

  • New member
  • *
  • Posts: 6
Android JNI Bridge
« on: April 30, 2017, 04:45:59 pm »
Hi. This example is the Delphi Android bridge system.

Code: Pascal  [Select]
  1. unit JavaInterfaces;
  2.  
  3. interface
  4.  
  5. uses
  6.   Androidapi.JNIBridge,
  7.   Androidapi.JNI.JavaTypes;
  8.  
  9. type
  10. // ===== Forward declarations =====
  11.  
  12.   JAppLibrary = interface;//com.zairovsoft.AppLibrary
  13.  
  14. // ===== Interface declarations =====
  15.  
  16.   JAppLibraryClass = interface(JObjectClass)
  17.     ['{3252901E-D765-4AC5-8FB7-FC7F2CA589C6}']
  18.     {class} function GetMsg(P1: JString): JString; cdecl;
  19.     {class} function init: JAppLibrary; cdecl;
  20.   end;
  21.  
  22.   [JavaSignature('com/zairovsoft/AppLibrary')]
  23.   JAppLibrary = interface(JObject)
  24.     ['{B4900D81-BD6D-4163-AC93-A7A62C496A6C}']
  25.   end;
  26.   TJAppLibrary = class(TJavaGenericImport<JAppLibraryClass, JAppLibrary>) end;
  27.  
  28. implementation
  29.  
  30. procedure RegisterTypes;
  31. begin
  32.   TRegTypes.RegisterType('JavaInterfaces.JAppLibrary', TypeInfo(JavaInterfaces.JAppLibrary));
  33. end;
  34.  
  35. initialization
  36.   RegisterTypes;
  37.  
  38. end.
  39.  

Code: Pascal  [Select]
  1. package com.zairovsoft;
  2.  
  3. public class AppLibrary
  4. {
  5.         public static String GetMsg(String value)
  6.         {
  7.                 return "AppLibrary: " + value;
  8.         }
  9. }
  10.  

Code: Pascal  [Select]
  1. ShowMessage(JStringToString(TJAppLibrary.JavaClass.GetMsg(StringToJString(Edit1.Text))));
  2.  

This is more useful. How would such a similar structure for Pascal be?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3537
Re: Android JNI Bridge
« Reply #1 on: May 17, 2017, 02:43:11 pm »
JNI is done in Free Pascal like this:

http://wiki.lazarus.freepascal.org/Android_Programming#Android_JNI

Does this answer your question?

AliZairov

  • New member
  • *
  • Posts: 6
Re: Android JNI Bridge
« Reply #2 on: May 17, 2017, 03:48:13 pm »
Hi. Thank you. I will examine.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus