Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Android连接蓝牙打印机?_Android_Delphi_Bluetooth_Android Bluetooth - Fatal编程技术网

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

如何使用Android连接蓝牙打印机?,android,delphi,bluetooth,android-bluetooth,Android,Delphi,Bluetooth,Android Bluetooth,我想使用David I在示例中描述的技术,通过Delphi将Android连接到蓝牙打印机 我的打印机是: 我得到一个错误: "java.io.IOException: read failed, socket might closed or timeout, read ret: -1" 通过sock.connect 这是我的密码: procedure TForm1.ListView1ItemClick(const Sender: TObject; const AItem: TListVie

我想使用David I在示例中描述的技术,通过Delphi将Android连接到蓝牙打印机

我的打印机是:

我得到一个错误:

"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转录了一个项目,使用了线程,一切正常。 不要使用计时器,请使用TThread对象