Answer the question
In order to leave comments, you need to log in
Why is it not connecting via bluetooth to the phone?
I'm trying to connect via bluetooth to my phone. Here is the connection code
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();
}
}
}
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());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question