Пытаюсь подключится по Bluetooth к телефону. Вот код подключения
private void Connect()
{
using (SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog())
{
bldialog.ShowAuthenticated = true;
bldialog.ShowRemembered = true;
bldialog.ShowUnknown = true;
if (bldialog.ShowDialog() == DialogResult.OK)
{
SetControlState(false);
tsStatusLabel.Text = "Operation started";
if (bldialog.SelectedDevice == null)
{
MessageBox.Show("No device selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress,
BluetoothService.ObexFileTransfer);
client = new BluetoothClient();
try
{
client.Connect(remoteEndPoint);
session = new ObexClientSession(client.GetStream(), UInt16.MaxValue);
session.Connect(ObexConstant.Target.FolderBrowsing);
}
catch (SocketException ex)
{
ExceptionHandler(ex, false);
return;
}
catch (ObjectDisposedException ex)
{
ExceptionHandler(ex, false);
return;
}
catch (IOException ex)
{
ExceptionHandler(ex, false);
return;
}
tsStatusLabel.Text = string.Format("Connected to: {0}", selecteddevice.DeviceName);
this.Text = string.Format("Bluetooth Device Browser. Current Device: {0}", selecteddevice.DeviceName);
tsiConnect.Enabled = tsbConnect.Enabled = false;
bgwWorker.RunWorkerAsync();
}
}
}
Выдает такую ошибку
connection failed требуемый адрес для своего контекста неверен
Пробовал также по другому ввести вручную адрес
static BluetoothAddress addr = BluetoothAddress.Parse("e8:6d:cb:7d:1d:b1"); //from device
BluetoothDeviceInfo device = new BluetoothDeviceInfo(addr);
device.SetServiceState(serviceClass, true);
Console.WriteLine(BluetoothSecurity.PairRequest(device.DeviceAddress, "0000")); //pairing my device - writes True
BluetoothEndPoint ep = new BluetoothEndPoint(addr, serviceClass);
BluetoothClient conn = new BluetoothClient(ep);
conn.Connect(ep);
Console.WriteLine(conn.GetStream());
Все равно та же ошибка