I would like to connect my Android device with my Windows device via Bluetooth with a RFCOMM serial port.
To figure out, if my App on Windows is started, I try to fetch the UUIDs of it with this code under Android:
var filter = new IntentFilter();
filter.AddAction(BluetoothDevice.ActionUuid);
RegisterFilter(filter);
_bluetoothManager = GetSystemService(Context.BluetoothService) as BluetoothManager;
… and inside the OnReceive method, I expect the result:
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == BluetoothDevice.ActionUuid)
{
var bluetoothDevice = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice, Class.FromType(typeof(BluetoothDevice)));
var items = intent.GetParcelableArrayExtra(BluetoothDevice.ExtraUuid, Class.FromType(typeof(ParcelUuid)));
...
}
}
I expect to get the UUID, I advise with my Windows APP:
var streamSocketListener = new StreamSocketListener();
streamSocketListener.ConnectionReceived += StreamSocketListener_ConnectionReceived;
var guid = Guid.Parse("12020AC9-7BDB-41CB-9B26-93A285E006AA");
var serviceId = RfcommServiceId.FromUuid(guid);
var rfcommServiceProvider = RfcommServiceProvider.CreateAsync(serviceId).AsTask().Result;
streamSocketListener.BindServiceNameAsync(rfcommServiceProvider.ServiceId.AsString()).AsTask().Wait();
rfcommServiceProvider.StartAdvertising(streamSocketListener);
Sometime, my Android App receives the UUID, but often not. Until now, I didn’t find out, when and when not.
Any idea, how I can get it stable?