藍芽API筆記

2021-07-25 00:08:57 字數 1296 閱讀 3154

bluetoothadapter 代表乙個藍芽介面卡硬體

通過bluetoothadapter 可以開啟/關閉藍芽介面卡 掃瞄周邊藍芽裝置…

bluetoothadapter = bluetoothadapter.getdefaultadapter();

開啟/關閉 藍芽裝置

bluetoothadapter.enable();  bluetoothadapter.disable();

操作藍芽裝置需要許可權

掃瞄/停止掃瞄藍芽裝置

bluetoothadapter.startdiscovery();

bluetoothadapter.canceldiscovery();

系統發現周邊的藍芽裝置會發乙個廣播

bluetoothdevice.action_found

監聽bluetoothdevice.action_found廣播 收到廣播後可以從intent中獲取到藍芽裝置

bluetoothdevice 代表乙個可以連線的藍芽硬體物件

通過bluetoothdevice可以獲得 bluetoothsocket物件

socket = device.createrfcommsockettoservicerecord(uuid.fromstring(

"00001101-0000-1000-8000-00805f9b34fb"));

獲得bluetoothsocket物件之後可以呼叫 connect();方法跟服務端建立連線

連線建立後可以通過 bluetoothsocket物件獲得輸入輸出流

建立藍芽連線步驟

① 通過bluetoothadapter開啟藍芽介面卡

② 通過bluetoothadapter.startdiscovery();掃瞄硬體

③ 建立廣播接收者監聽bluetoothdevice.action_found廣播 獲得bluetoothdevice物件

④ 通過device.createrfcommsockettoservicerecord(uuid uuid);獲得bluetoothsocket

⑤ bluetoothsocket 的connect();方法 連線到藍芽裝置

⑥ 通過bluetoothsocket獲得輸入輸出流 通過流傳遞資料

WinCE藍芽控制API函式

對於藍芽的設定還可以直接使用現有的api函式 bthsetmode bthgetmode 這兩個函式定義在 bthutil.h,然後需要新增依賴的lib庫 bthutil.lib int bthsetmode dword dwmode int bthgetmode dword pdwmode ret...

WinCE藍芽控制API函式

對於藍芽的設定還可以直接使用現有的api函式 bthsetmode bthgetmode 這兩個函式定義在 bthutil.h,然後需要新增依賴的lib庫 bthutil.lib int bthsetmode dword dwmode int bthgetmode dword pdwmode ret...

藍芽學習筆記

1.藍芽4.0技術總結 a.傳統藍芽技術 b.藍芽低功耗技術 版本新增 c.高速藍芽技術 24mbit s 2.藍芽低功耗優點 a.低成本 b.跨廠商互操作性 c.3ms低延時 d.100m以上超長距離 e.aes 128加密3.藍芽版本差異 a.藍芽1.1與藍芽1.2傳輸速度慢 1mbit s 抗...