Since i'm currently working with automated testing of windows devices I need to test bluetooth capability of DUT (Device under test), using built-in libraries from Windows 10 (build 10536), because devices are factory reset before testing. For testing I made custom UWP app to test different aspects of device. Now I'm messing with bluetooth. For testing purposes i have n-amount of bluetooth (rfComm) devices and device needs to automatically connect to selected bluetooth device (sent from different device, this part is already developed). No I need to make part which upon request from TCP, an app scans for unpaired devices and pairs with certain one (given with ID).
Scan result is collected in observablecollection.
My current try on pairing with device:
public async Task<int> PairWithSelectedAsync(string SSIDToPairWith)
{
int returnvalue = 0;
foreach (RfcommChatDeviceDisplay rfcommInfoDisp in ResultCollection)
{
if (rfcommInfoDisp.Id == SSIDToPairWith)
{
Debug.WriteLine("Found device to connect to");
Debug.WriteLine(rfcommInfoDisp.Name);
Debug.WriteLine(rfcommInfoDisp.Id);
if(rfcommInfoDisp.DeviceInformation.Pairing.CanPair == true)
{
//rfcommInfoDisp.DeviceInformation.Properties.
DevicePairingResult pairingResult= await rfcommInfoDisp.DeviceInformation.Pairing.PairAsync();
if(pairingResult.Status == 0)
{
Debug.WriteLine("Connected");
returnvalue = 0;
}
else
{
returnvalue = (int)pairingResult.Status;
}
}
//Debug.WriteLine("\n");
}
}
return returnvalue;
}
Now current problem is: This kind of pairing requires user prompt to continue: popup appears on screen and operator needs to tap it. Is it possible to modify current code in a way it doesn't need prompt to pair with device?
I also looked this thread but it seems this solution doesn't work with "stock" library: Pairing with 32feetnet Also This topic seems to be dead end without anyone finding answer from there. Any suggestion or help is appreciated.