android - 如何使用 Android 连接蓝牙打印机?

标签 android delphi bluetooth android-bluetooth

我想使用 Bluetooth Paired Devices Browser 中描述的技术将 Android 连接到带有 Delphi 的蓝牙打印机。 David I 的例子。

我的打印机是 Panda BIXOLON SPP-R200II :

我得到错误:

"java.io.IOException: read failed, socket might closed or timeout, read ret: -1"

通过 sock.connect;

这是我的代码:

procedure TForm1.ListView1ItemClick(const Sender: TObject;
  const AItem: TListViewItem);
begin

  ShowMessage('You selected: '+Aitem.Text);

  // depending on the bluetooth device selected - do something with it
  targetMACAddress:=Aitem.Detail;
  if trim(targetMACAddress)='' then exit;

  Adapter:=TJBluetoothAdapter.JavaClass.getDefaultAdapter;
  remoteDevice:=Adapter.getRemoteDevice(stringtojstring(targetMACAddress));
  sock:=remoteDevice.createRfcommSocketToServiceRecord(UID);
  try
    sock.connect;
  except
  on E : Exception do
    ShowMessage(E.Message);
  end;
  if not sock.isConnected then
  begin
    ShowMessage('Failed to connect to Try again...');
    exit;
  end;
  listview1.Visible:=false;     // hide the chooser
  label1.Visible:=false;        // hide the chooser
  reload.Visible:=false;        // hide the chooser
end;

最佳答案

与蓝牙设备进行的所有通信都必须通过线程 进行。
我在 Android Studio 中为 Delphi 转录了一个项目,使用线程,一切正常。 不要使用 Timer,使用 TThread 对象。

关于android - 如何使用 Android 连接蓝牙打印机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24569607/

相关文章:

c++ - 跨平台信息

java - 如何从文件中检索特定字符串? (安卓)

java - 将 .jar 文件上传到远程存储库

delphi - 如何将格式化为以下格式的字符串转换为TDateTime:15h44m28s?

ios - Swift Core蓝牙 : Should CentralManager run in a separate thread?

python - 在 ZeroMQ/Tornado ioloop 或 Twisted 中使用 BluetoothSocket?

android - 当蓝牙连接到我的设备时,是否可以在应用程序中收到通知?

android - 按下电源按钮时 Asynctask 音乐不会停止

Android:更改 fragment 的背景颜色

c++ - C/C++ 中 Delphi 类型的类比