I'am trying to send simple string message via bluetooth to another device. My code looks like this:
private ICollection<BluetoothDevice> devicesArray;
private void SendBtn_Click(object sender, EventArgs e)
{
BluetoothDevice bd = null;
foreach(var o in PairedListView.pairedDevices)
{
if(o.Selected == true)
{
bd = getPairedDevice(o.DeviceAddress);
break;
}
}
if(bd != null)
{
UUID uuid = UUID.FromString("00001101-0000-1000-8000-00805f9b34fb");
BluetoothSocket socket = bd.CreateRfcommSocketToServiceRecord(uuid);
socket.Connect();
Stream stream = socket.OutputStream;
byte[] array = Encoding.ASCII.GetBytes("Testing message!");
stream.Write(array, 0, array.Length);
socket.Close();
}
else
{
Alerts.showAlertMessage("Choose device", this);
}
}
private BluetoothDevice getPairedDevice(string address)
{
BluetoothDevice bd = null;
foreach(var o in devicesArray)
{
if(o.Address == address)
{
bd = o;
break;
}
}
return bd;
}
I'am expecting receive string message on choosen device. The problem is I'am getting error
Java.IO.IOException: Service discovery failed
When trying to connect. Could You tell me what I'am doing wrong?