新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS傳統(tǒng)藍牙遠端設(shè)備操作
場景介紹

傳統(tǒng)藍牙遠端管理操作主要是針對遠端藍牙設(shè)備的基本操作,包括獲取遠端藍牙設(shè)備地址、類型、名稱和配對狀態(tài),以及向遠端設(shè)備發(fā)起配對。
接口說明
| 接口名 | 功能描述 |
|---|---|
| getDeviceAddr() | 獲取遠端藍牙設(shè)備地址。 |
| getDeviceClass() | 獲取遠端藍牙設(shè)備類型。 |
| getDeviceName() | 獲取遠端藍牙設(shè)備名稱。 |
| getPairState() | 獲取遠端設(shè)備配對狀態(tài)。 |
| startPair() | 向遠端設(shè)備發(fā)起配對。 |
開發(fā)步驟
- 調(diào)用 BluetoothHost 的 getDefaultHost(Context context)接口,獲取 BluetoothHost 實例,管理本機藍牙操作。
- 調(diào)用 enableBt() 接口,打開藍牙。
- 調(diào)用 startBtDiscovery(),掃描設(shè)備。
- 調(diào)用 startPair(),發(fā)起配對。
// 獲取藍牙本機管理對象
BluetoothHost bluetoothHost = BluetoothHost.getDefaultHost(context);
// 調(diào)用打開接口
bluetoothHost.enableBt();
// 調(diào)用掃描接口
bluetoothHost.startBtDiscovery();
//設(shè)置界面會顯示出掃描結(jié)果列表,點擊藍牙設(shè)備去配對
BluetoothRemoteDevice device = bluetoothHost.getRemoteDev(TEST_ADDRESS);
device.startPair(); 網(wǎng)頁標題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS傳統(tǒng)藍牙遠端設(shè)備操作
當前URL:http://m.fisionsoft.com.cn/article/cdhijhe.html


咨詢
建站咨詢
