我想使用 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/