語言

BluetoothDevice 類別

定義

代表藍牙裝置。

使用此類別的範例應用包括 裝置列舉與配對範例 ,以及 藍牙 RFCOMM 聊天範例。

public ref class BluetoothDevice sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class BluetoothDevice final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class BluetoothDevice : System.IDisposable
Public NotInheritable Class BluetoothDevice
Implements IDisposable
繼承
Object Platform::Object IInspectable BluetoothDevice
屬性
實作

Windows 需求

規格需求 Description
裝置系列
Windows 10 (已於 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
應用程式功能
bluetooth

備註

版本歷程記錄

Windows版本 SDK 版本 附加價值
1511 10586 裝置資訊
1511 10586 GetDeviceSelectorFromBluetoothAddress
1511 10586 GetDeviceSelectorFromClassOfDevice
1511 10586 GetDeviceSelectorFromConnectionStatus
1511 10586 GetDeviceSelectorFromDeviceName
1511 10586 GetDeviceSelectorFromPairingState
1607 14393 裝置存取資訊
1607 14393 GetRfcommServicesAsync
1607 14393 GetRfcommServicesAsync(BluetoothCacheMode)
1607 14393 GetRfcommServicesForIdAsync(RfcommServiceId)
1607 14393 GetRfcommServicesForIdAsync(RfcommServiceId,BluetoothCacheMode)
1607 14393 請求存取非同步
1709 16299 藍牙裝置識別
1803 17134 Was SecureConnection用於配對

屬性

名稱 Description
BluetoothAddress

取得裝置位址。

BluetoothDeviceId

會取得藍牙裝置 ID。

ClassOfDevice

取得裝置的藍牙類別資訊。

ConnectionStatus

會取得裝置的連線狀態。

DeviceAccessInformation

目前裝置的 DeviceAccessInformation 物件。 用來檢查和監控裝置的存取變更。

DeviceId

取得來自 Windows 的裝置 ID。Devices.Enumeration.DeviceInformation.Id

DeviceInformation

取得藍牙裝置的 DeviceInformation 物件。

HostName

會取得裝置的主機名稱。

Name

會取得裝置名稱。

RfcommServices

取得裝置支援的唯讀 RFCOMM 服務清單。

Important

RfcommServices API 已被棄用,未來的 Windows 版本可能無法提供。 相反地,請使用 GetRfcommServicesAsync。

SdpRecords

取得該裝置的唯讀服務發現協定(SDP)紀錄清單。

WasSecureConnectionUsedForPairing

會收到一個布林值,顯示藍牙裝置是否使用安全連線配對。

方法

名稱 Description
Close()

關閉藍牙裝置。

Dispose()

執行與釋放、釋放或重設非受控資源相關聯的應用程式定義工作。

FromBluetoothAddressAsync(UInt64)

會回傳給定的 BluetoothDevice 物件。

FromHostNameAsync(HostName)

回傳一個以 HostName 識別的 BluetoothDevice 物件。

FromIdAsync(String)

回傳一個以指定 DeviceID 識別的 BluetoothDevice 物件。

GetDeviceSelector()

會取得進階查詢語法(AQS)字串以識別此裝置的實例。 此字串會傳遞給 FindAllAsync 或 CreateWatcher 方法。

GetDeviceSelectorFromBluetoothAddress(UInt64)

從代表藍牙裝置的 64 位元位址建立一個進階查詢語法(AQS)過濾字串。 AQS 字串會被傳遞到 CreateWatcher 方法,以回傳一組 DeviceInformation 物件。

GetDeviceSelectorFromClassOfDevice(BluetoothClassOfDevice)

從 BluetoothClassOfDevice 物件建立進階查詢語法(AQS)過濾字串。 AQS 字串會被傳遞到 CreateWatcher 方法,以回傳一組 DeviceInformation 物件。

GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus)

建立一個進階查詢語法(AQS)過濾字串,包含帶有 BluetoothConnectionStatus 的藍牙裝置查詢。 AQS 字串會被傳遞到 CreateWatcher 方法,以回傳一組具有藍牙連線狀態的 DeviceInformation 物件集合。

GetDeviceSelectorFromDeviceName(String)

建立一個進階查詢語法(AQS)過濾字串,內含藍牙裝置名稱的查詢。 AQS 字串會被傳遞到 CreateWatcher 方法,以回傳包含指定藍牙裝置名稱的 DeviceInformation 物件集合。

GetDeviceSelectorFromPairingState(Boolean)

建立一個進階查詢語法(AQS)過濾字串,包含對藍牙裝置的查詢,無論是配對中還是未配對中。 AQS 字串會被傳遞到 CreateWatcher 方法,以回傳一組 DeviceInformation 物件。

GetRfcommServicesAsync()

擷取遠端藍牙裝置上的所有 Rfcomm 服務。

GetRfcommServicesAsync(BluetoothCacheMode)

擷取遠端藍牙裝置上所有快取的 Rfcomm 服務。

GetRfcommServicesForIdAsync(RfcommServiceId, BluetoothCacheMode)

擷取遠端藍牙裝置上所有符合指定 RfcommServiceID 的快取 Rfcomm 服務。

GetRfcommServicesForIdAsync(RfcommServiceId)

擷取遠端藍牙裝置上所有符合指定 RfcommServiceID 的 Rfcomm 服務。

RequestAccessAsync()

用來要求明確存取藍牙裝置。 這會觸發裝置同意,必須在 UI 執行緒中呼叫。

事件

名稱 Description
ConnectionStatusChanged

當裝置的連線狀態改變時,會發生這種情況。

NameChanged

當裝置名稱更改時會發生。

SdpRecordsChanged

當裝置的清單 SDP 記錄變更時會發生。

適用於

另請參閱