在Delphi中使用第三方Android API

时间:2021-06-22 21:46:41

I am trying to use a Honeywell SDK in Delphi Seattle to control a scanner on an Android device.

我正在尝试在Delphi Seattle中使用Honeywell SDK来控制Android设备上的扫描仪。

Honeywell provided me with a SDK jar called DataCollection.jar. I used the Java2OP utility to create my JNI bridge but am having trouble with it. To be honest I am a novice on this and am not sure where to look or how to implement this. I have searched for similar examples too.

霍尼韦尔为我提供了一个名为DataCollection.jar的SDK jar。我使用Java2OP实用程序来创建我的JNI桥,但是遇到了麻烦。说实话,我是一个新手,我不知道在哪里看或如何实现这一点。我也搜索过类似的例子。

I know I have to create an object of type TJAidmanager to access the barcode reader functions , it is defined as :

我知道我必须创建一个TJAidmanager类型的对象来访问条形码阅读器功能,它被定义为:

JAidcManagerClass = interface(JObjectClass)
['{EE70EF80-4CA8-4FE0-B912-6453CA0336CD}']
{class} function _GetBARCODE_DEVICE_CONNECTED: Integer; cdecl;
{class} function _GetBARCODE_DEVICE_DISCONNECTED: Integer; cdecl;
{class} procedure addBarcodeDeviceListener(P1:      JAidcManager_BarcodeDeviceListener); cdecl;
{class} procedure close; cdecl;
{class} procedure create(P1: JContext; P2: JAidcManager_CreatedCallback);    cdecl;
{class} function createBarcodeReader: JBarcodeReader; cdecl; overload;
{class} function createBarcodeReader(P1: JString): JBarcodeReader; cdecl;     overload;
{class} function listBarcodeDevices: JList; cdecl;
{class} function listConnectedBarcodeDevices: JList; cdecl;
{class} procedure removeBarcodeDeviceListener(P1:    JAidcManager_BarcodeDeviceListener); cdecl;
{class} property BARCODE_DEVICE_CONNECTED: Integer read     _GetBARCODE_DEVICE_CONNECTED;
{class} property BARCODE_DEVICE_DISCONNECTED: Integer read   _GetBARCODE_DEVICE_DISCONNECTED;
end;

[JavaSignature('com/honeywell/aidc/AidcManager')]
JAidcManager = interface(JObject)
['{98A668C5-9204-4F0C-98B0-A8E1F1124738}']
end;
TJAidcManager = class(TJavaGenericImport<JAidcManagerClass, JAidcManager>)    end;

The java sample code looks like this :

java示例代码如下所示:

import com.honeywell.aidc.*;
public class MainActivity extends Activity {
private AidcManager manager;
private BarcodeReader reader;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// create the AidcManager providing a Context and an
// CreatedCallback implementation.
AidcManager.create(this, new AidcManager.CreatedCallback() {

@Override
public void onCreated(AidcManager aidcManager) {
manager = aidcManager;
reader = manager.createBarcodeReader();
}
}
}

@Override
public void onDestroy() {
super.onDestroy();
// make sure that AidcManager isn't null
if (reader != null) {
// close BarcodeReader to clean up resources.
// once closed, the object can no longer be used.
reader.close();
}
if (manager != null) {
// close AidcManager to disconnect from the scanner service.
// once closed, the object can no longer be used.
manager.close();
}
}
}

Now when I try and use this in delphi , I have tried this but get a segmentation fault :

现在,当我尝试在delphi中使用它时,我尝试了这个但是得到了一个分段错误:

var cb : JAidcManager_CreatedCallback;
begin
      TJAidcManager.JavaClass.create(SharedActivity,TJAidcManager_CreatedCallback.Wrap((cb as ILocalObject).getobjectID));

The JAidcManager_CreatedCallback is defined as :

JAidcManager_CreatedCallback定义为:

 JAidcManager_CreatedCallbackClass = interface(IJavaClass)
    ['{E27EF6BB-C642-42B6-98CA-6C270A1AD5D1}']
    {class} procedure onCreated(P1: JAidcManager); cdecl;//Deprecated
  end;

  [JavaSignature('com/honeywell/aidc/AidcManager$CreatedCallback')]
  JAidcManager_CreatedCallback = interface(IJavaInstance)
    ['{E2713D70-1CE6-43AA-9181-7054BD787F1B}']
  end;
  TJAidcManager_CreatedCallback =   class(TJavaGenericImport<JAidcManager_CreatedCallbackClass,   JAidcManager_CreatedCallback>) end;

I assume I have to implement an onCreated Event for a variable of type TJAidcManager but I am not sure how to link these all together.

我假设我必须为TJAidcManager类型的变量实现onCreated事件,但我不确定如何将它们全部链接在一起。

I then tried this :

然后我尝试了这个:

var   cb : JObject;
begin
  cb := TjObject.Create;
  TJAidcManager.JavaClass.create(SharedActivityContext,TJAidcManager_CreatedCallback.Wrap((cb as ILocalObject).getobjectID));

I also added this to the JNIBridge Unit in the implementation section :

我还在实现部分将其添加到JNIBridge单元:

procedure onCreated(P1: JAidcManager); cdecl;//Deprecated
begin
   Form2.manager := P1;
end;

When running this, I get a "java.lang.SecurityException: Not allowed to bind to service Intent {acct=com.honeywell.decode.DecodeService cmp=com.intermec.datacollectionservice/.DataCollectionService}" error. I tried adding "Bind Remoteviews" to permissions but that didn't help.

运行时,我得到一个“java.lang.SecurityException:不允许绑定到服务Intent {acct = com.honeywell.decode.DecodeService cmp = com.intermec.datacollectionservice / .DataCollectionService}”错误。我尝试将“绑定远程视图”添加到权限,但这没有帮助。

If anyone could advise me or point me in the correct direction on how to create the AidcManager in Delphi, that would be appreciated.

如果有人可以建议我或指出如何在Delphi中创建AidcManager的正确方向,那将不胜感激。

1 个解决方案

#1


-1  

This problem has been solved. I needed to extend the com.embarcadero.firemonkey.FMXNativeActivity.

这个问题已经解决了。我需要扩展com.embarcadero.firemonkey.FMXNativeActivity。

The details of the full solution can be found here Embaradero Forum with link to Source

完整解决方案的详细信息可以在Embaradero论坛中找到,链接到Source

#1


-1  

This problem has been solved. I needed to extend the com.embarcadero.firemonkey.FMXNativeActivity.

这个问题已经解决了。我需要扩展com.embarcadero.firemonkey.FMXNativeActivity。

The details of the full solution can be found here Embaradero Forum with link to Source

完整解决方案的详细信息可以在Embaradero论坛中找到,链接到Source