經典藍芽與低功耗藍芽掃瞄

2021-09-29 10:21:18 字數 1144 閱讀 8754

//初始化ble設配器

bluetoothmanager manager = (bluetoothmanager) getsystemservice(context.bluetooth_service);

bluetoothadapter mbluetoothadapter = manager.getadapter();

//判斷藍芽是否開啟,如果關閉則請求開啟藍芽

if (mbluetoothadapter == null || !mbluetoothadapter.isenabled())

if (bluetoothadapter.isdiscovering())

android 4.3 掃瞄

在android 4.3 和 android 4.4進行藍芽掃瞄中,可使用bluetoothadapter.startlescan(bluetoothadapter.lescancallback)進行藍芽掃瞄。

//開始掃瞄

mbluetoothadapter.startlescan(mlescancallback);

//停止掃瞄

mbluetoothadapter.stoplescan(mlescancallback);

android 5.0以上 掃瞄

在 android 5.0之後的版本(包括 5.0)建議使用新的api進行藍芽掃瞄:

bluetoothlescanner.startscan(scancallback)或

bluetoothlescanner.startscan(list, scansettings, scancallback)。

//獲取 5.0 的掃瞄類例項

mblescanner = mbluetoothadapter.getbluetoothlescanner();

//開始掃瞄

//可設定過濾條件,在第乙個引數傳入,但一般不設定過濾。

mblescanner.startscan(null,mscansettings,mscancallback);

//停止掃瞄

mblescanner.stopscan(mscancallback);

android 6.0 以上需要獲取到定位許可權。否則會造成掃瞄不到。

demo位址 低功耗4.3

低功耗5.0

藍芽學習(一) 低功耗藍芽和經典藍芽概述

經典藍芽 classic bluetooth 和低功耗藍芽 bluetooth low energy,簡稱ble或者le 兩者有什麼區別?為什麼他們都叫 藍芽 bluetooth low energy和bluetooth smart兩者又有什麼區別?我的應用到底該選經典藍芽技術還是低功耗藍芽技術?這...

低功耗藍芽簡述

低功耗藍芽 ble 在功耗問題上大大區別於其舊版本 bt 1.0,基本位元速率,1mbps bt 2.0,增強位元速率,3mbps bt 3.0,交替射頻,24mbps bt 4.0,相容低功耗模式,ble 物理層1mbps 經典藍芽 bt 4.2 有意義的低功耗設計通常會應用在電池供電的場合,低功...

經典藍芽和低功耗藍芽(BLE)有什麼區別?

藍芽模組bluetooth module 是指整合藍芽功能的晶元基本電路集合,用於短距離2.4g的無線通訊模組。對於終端使用者來說,藍芽模組是半成品,通過在模組的基礎上功能再開發 封裝外殼等工序,實現能夠利用藍芽通訊的最終產品。藍芽模組也按照應用和支援協議分為主要兩種,不同型別的 定位 功能各有不同...