Я нашел способ ..
Сначала откройте намерение перевести Bluetooth в режим обнаружения ...
var intent = new Intent(BluetoothAdapter.ActionRequestDiscoverable);
StartActivityForResult(intent, 0);
Затем используйте ListenUsingInsecureRfcommWithServiceRecord, чтобы перевести BT в режим прослушивания:
class BluetoothThread : Java.Lang.Thread
{
BluetoothServerSocket _btServerSocket;
BluetoothSocket _btSocket;
Stream _inStream;
Stream _outStream;
private static Java.Util.UUID uuid = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
public event EventHandler<String> OnStringReceived;
public bool Cancel { get; set; } = false;
public override void Run()
{
byte[] buffer = new byte[1024];
int bytes;
string _ReceivedStr;
try
{
_btServerSocket =
BluetoothAdapter.DefaultAdapter.ListenUsingInsecureRfcommWithServiceRecord("Test.Droid", uuid);
try
{
_btSocket = _btServerSocket.Accept();
if (_btServerSocket != null)
Log.Info("BluetoothThread", "CONNECTION SUCCEED!");
_inStream = _btSocket.InputStream;
_outStream = _btSocket.OutputStream;
}
catch (Java.IO.IOException e)
{
Log.Error("BluetoothThread", "accept() failed", e);
}
while (!Cancel)
{
// Read from the InputStream
bytes = _inStream.Read(buffer, 0, buffer.Length);
_ReceivedStr = Encoding.ASCII.GetString(buffer);
OnStringReceived?.Invoke(this, _ReceivedStr);
Log.Info("BluetoothThread", $"RECEIVED: {_ReceivedStr}");
}
}
catch (Java.IO.IOException e)
{
Log.Error("BluetoothThread", "listen() failed", e);
}
}
}