问题
I tried two different approaches to connect to Bluetooth device in windows 10. 1)Developed an application with 32feetnet and tried to connect to Bluetooth device, it is prompting with whether pin is matched or not message box. 2. Created a sample Universal Windows program(UWP) to connect to Bluetooth device, it is prompting with whether pin is matched or not message box.
Is there any away to avoid the pin prompting message box.
回答1:
EventHandler authHandler = new EventHandler(handleAuthRequests); BluetoothWin32Authentication authenticator = new BluetoothWin32Authentication(authHandler);
private void btnPairSSP_Click(object sender, EventArgs e)
{
BluetoothDeviceInfo selectedDevice = devices[lstBTDevices.SelectedIndex];
if (MessageBox.Show(String.Format("Would you like to attempt to pair with {0}?", selectedDevice.DeviceName), "Pair Device", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Task t = new Task(PairBluetoothTask);
t.Start();
}
}
private void PairBluetoothTask()
{
BluetoothDeviceInfo selectedDevice = devices[lstBTDevices.SelectedIndex];
if (BluetoothSecurity.PairRequest(selectedDevice.DeviceAddress, null))
{
MessageBox.Show("We paired!");
}
else
{
MessageBox.Show("Failed to pair!");
}
}
private void handleAuthRequests(object sender, BluetoothWin32AuthenticationEventArgs e)
{
e.Confirm = true;
}
来源:https://stackoverflow.com/questions/51974013/not-to-display-pairing-pop-up-mssage-during-bluetooth-pairing-with-32feetnet-in