问题
There are some odd ways, like checking for pair devices and catching exceptions to see it if is on or not.
if ((uint)ex.HResult == 0x8007048F)
{
var result = MessageBox.Show("Bluetooth is turned off.\nTo see the current Bluetooth settings tap 'ok'", "Bluetooth Off", MessageBoxButton.OKCancel);
}
But I see there is a new BluetoothConnectionStatus api but don't know how to use it.
How to check bluetooth status in Windows Phone Runtime apps?
回答1:
It's probably something like this:
using Windows.Devices.Bluetooth;
// look for any paired device
PeerFinder.AllowBluetooth = true;
// start looking for BT devices
PeerFinder.Start();
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
// get the list of paired devices
var peers = await PeerFinder.FindAllPeersAsync();
var peer = peers.First(p => p.DisplayName.Contains("my_bt_device_name"));
var bt = await BluetoothDevice.FromHostNameAsync(peer.HostName);
if (bt.ConnectionStatus == BluetoothConnectionStatus.Connected)
{
// My device is connected
}
来源:https://stackoverflow.com/questions/23545233/how-to-check-status-of-bluetooth-in-windows-runtime