I'm developing POS app which will be used on A920 payment terminal.
Vendor supplied jar file and I used java2op and generated bridge file.
Documentation have android example
public static final String AIDL_ACTION = "rs.asoft.asoftposandroid.util.service.AIDL";
public static final String AIDL_PACKAGE = "rs.asoft.asoftposandroid";
private IAsoftPOS common;
private ServiceConnection serviceConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service)
{ common = IAsoftPOS.Stub.asInterface(service);
Log.d("ServiceConnection", "Successful connection");
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d("ServiceConnection", "The connection has been lost");
}
};
//The implicit Intent must be converted to the explicit:
private Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent)
{ PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfoList == null || resolveInfoList.size() != 1) return null;
ResolveInfo serviceInfo = resolveInfoList.get(0);
ComponentName componen = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name);
Intent exlicitIntent = new Intent(implicitIntent);
exlicitIntent.setComponent(componen); return exlicitIntent;
}
//Connecting:
Intent intent = new Intent(IAsoftPOS.class.getName());
intent.setAction(AIDL_ACTION); intent.setPackage(AIDL_PACKAGE);
bindService(convertImplicitIntentToExplicitIntent(intent), serviceConn, BIND_AUTO_CREATE);
//Calling method messageExchange:
byte[] response = common.messageExchange(tlvCommand);
As total noob with this, I managed to convert to delphi
function ConvertImplicitIntentToExplicitIntent(implicitIntent: JIntent): JIntent;
var
PM: JPackageManager;
ResolveInfoList: JList;
ServiceInfo: JResolveInfo;
Componen: JComponentName;
ExplicitIntent: JIntent;
begin
PM := TAndroidHelper.Context.getPackageManager;
ResolveInfoList := PM.queryIntentServices(implicitIntent, 0);
if (ResolveInfoList = nil) or (ResolveInfoList.size <> 1) then
Exit(nil);
ServiceInfo := TJavaObjectArray<JResolveInfo>.Wrap((ResolveInfoList as ILocalObject).GetObjectID).Items[0];
Componen := TJComponentName.JavaClass.init(ServiceInfo.ServiceInfo.packageName, ServiceInfo.ServiceInfo.name);
ExplicitIntent := TJIntent.JavaClass.init(implicitIntent);
ExplicitIntent.setComponent(Componen);
Result := ExplicitIntent;
end;
And I'm stuck with ServiceConnection as I need to assign OnServiceConnected.
var
Common: JIAsoftPOS;
ServiceConnection: JServiceConnection;
procedure TfmPostTest.Button1Click(Sender: TObject);
Var
Intent: JIntent;
Response: TJavaArray<Byte>;
sendCommand: string;
i: Integer;
begin
Intent := TJIntent.Create;
Intent.setAction(StringToJString(AIDL_ACTION));
Intent.setPackage(StringToJString(AIDL_PACKAGE));
TAndroidHelper.Context.bindService(ConvertImplicitIntentToExplicitIntent(Intent), ServiceConnection,
TJContext.JavaClass.BIND_AUTO_CREATE);
Response := Common.messageExchange(StringToJA(IspisiracunTest));
if Response <> nil then
for i := 0 to Response.length - 1 do
sendCommand := sendCommand + IntToHex(Response[i]);
showMessage(sendCommand);
end;
Si If anyone can look at it, greatly appreciated. I'm prepared to pay for the services as I'm on very tight schedule.
Boris
A920.zip