我可以知道是否允许我的应用与 UWP 中未配对的设备配对吗?

Can I know if my app is allowed to pair with unpaired devices in UWP?

我正在使用 BluetoothLEAdvertisementWatcher 来监视蓝牙低功耗信标。 如果用户禁用选项 "Communicate with unpaired devices" (ms-settings:privacy-customdevices),我的应用将永远不会获得任何信标。

是否可以检查此选项是否已启用,或要求用户启用此选项?

我还没有找到直接检查的方法,但如果用户禁用此选项,调用观察者的 Start 方法,它将立即中止,错误代码为 DisabledByUser。您可以在 Bluetooth Advertisment sample in UWP samples repo.

中看到实际效果

您可以在观察者上订阅 Stopped 事件,然后检查 BluetoothLEAdvertisementWatcherStoppedEventArgs.Error 以查看用户是否禁用它:

private async void OnAdvertisementWatcherStopped(
    BluetoothLEAdvertisementWatcher watcher, 
    BluetoothLEAdvertisementWatcherStoppedEventArgs eventArgs)
{
    if (watcher.Status == BluetoothLEAdvertisementWatcherStatus.Aborted)
    {
        if (eventArgs.Error == BluetoothError.DisabledByUser) 
        { 
           // do something - show dialog to open settings, etc.
        }
    }
}

您可以要求用户使用对话框消息启用应用程序访问权限,并通过执行 Launch.LaunchUriAsync("ms-settings:privacy-customdevices").

将他们重定向到“设置”应用程序