我想使用Delphi的蓝牙打印机连接Android,使用David I的Bluetooth Paired Devices Browser示例中描述的技术。
我的打印机是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;
答案 0 :(得分:1)
必须通过主题进行与蓝牙设备进行的所有通信。
我在Android Studio for Delphi中使用线程转录了一个项目,一切正常。
不要使用Timer,使用TThread对象。