【问题标题】:Delphi connect print service via AIDLDelphi 通过 AIDL 连接打印服务
【发布时间】:2019-10-14 22:09:54
【问题描述】:

我想在 Delphi 中使用这个 Android 代码:

Intent intent = new Intent();
intent.setPackage("com.sunmi.extprinterservice");
intent.setAction("com.sunmi.extprinterservice.PrinterService");
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);

ServiceConnection serviceConnection = new ServiceConnection()
{
    @Override
    public void onServiceConnected(ComponentName name, IBinder service)
    {
        ExtPrinterService interface = ExtPrinterService.Stub.asInterface(service);
    }

    @Override
    public void onServiceDisconnected(ComponentName name)
    {
    }
};

使用接口对象实现自己的打印任务

interface.printText(“123456\n”);

使用完成后解除绑定服务

unbindService(serviceConnection);

【问题讨论】:

  • 您好,这篇文章可以从更多细节中受益。我并不清楚问题是什么。例如,它是否正常工作,或者是否引发错误(如果是,请包括在内)。
  • @JeffMergler 我认为 OP 正在询问如何将此 Java 代码转换为 Delphi Pascal 代码。
  • 好的@remy-lebeau

标签: android delphi android-intent


【解决方案1】:

这是我的第一次尝试。我没有办法测试这个。我也没有办法访问ExtPrinterService。这显然是另一回事,可能是清单声明和库导入步骤。至少,一旦您了解了如何使用接口,您就可以看到一些 Java 代码以直接的方式转换为 Delphi。

uses
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  Androidapi.Helpers,
  Androidapi.JNIBridge,
  Androidapi.JNI.App,
  Androidapi.JNI.Os

procedure TTabbedForm.FormCreate(Sender: TObject);
var
  Intent: JIntent;
  ServiceConnection: JServiceConnection;
begin

  Intent := TJIntent.Create;
  Intent.setPackage(StringtoJString('com.sunmi.extprinterservice'));
  Intent.setAction(StringtoJString('com.sunmi.extprinterservice'));

  ServiceConnection := TJServiceConnection.Create;
  ServiceConnection.onServiceConnected := OnServiceConnected;
  ServiceConnection.onServiceDisconnected := OnServiceDisconnected;
  SharedActivityContext.bindService(Intent, ServiceConnection, TJContext.JavaClass.BIND_AUTO_CREATE);

end;

procedure TTabbedForm.OnServiceConnected(name: JComponentName; Binder: JIBinder);
begin
  //
end;

procedure TTabbedForm.OnServiceDisconnected(name: JComponentName);
begin
  //
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 2019-07-22
    • 2012-02-05
    • 2020-03-01
    • 2019-09-16
    相关资源
    最近更新 更多