Android7.1打开蓝牙ble
1.system/bt目录:
diff --git a/include/bt_target.h b/include/bt_target.h old mode 100644 new mode 100755 index b0cf856..d4d1556 --- a/include/bt_target.h +++ b/include/bt_target.h @@ -688,14 +688,14 @@ * resolution, local address rotation etc. */ #ifndef BLE_PRIVACY_SPT -#define BLE_PRIVACY_SPT FALSE +#define BLE_PRIVACY_SPT TRUE #endif /* * Enables or disables support for local privacy (ex. address rotation) */ #ifndef BLE_LOCAL_PRIVACY_ENABLED -#define BLE_LOCAL_PRIVACY_ENABLED TRUE +#define BLE_LOCAL_PRIVACY_ENABLED FALSE #endif /* @@ -703,7 +703,7 @@ * feature discovery, multi-adv etc. */ #ifndef BLE_VND_INCLUDED -#define BLE_VND_INCLUDED FALSE +#define BLE_VND_INCLUDED TRUE #endif
不加以上这些修改,可以搜到ble设备,但是会连接不成功。
2.farmeworks/base目录:
--- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -909,13 +909,16 @@ public final class BluetoothAdapter { * @return true if Multiple Advertisement feature is supported */ public boolean isMultipleAdvertisementSupported() { - if (getState() != STATE_ON) return false; + /* + if (getState() != STATE_ON) return false; try { return mService.isMultiAdvertisementSupported(); } catch (RemoteException e) { Log.e(TAG, "failed to get isMultipleAdvertisementSupported, error: ", e); } return false; + */ + return true; }
--- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1102,7 +1102,7 @@ <bool name="config_bluetooth_address_validation">false</bool> <!-- Boolean indicating if current platform supports BLE peripheral mode --> - <bool name="config_bluetooth_le_peripheral_mode_supported">false</bool> + <bool name="config_bluetooth_le_peripheral_mode_supported">true</bool> <!-- Max number of scan filters supported by blutooth controller. 0 if the device does not support hardware scan filters-->
加上些,就可以正常搜索ble设备并连接成功了。
注意点:手机端搜索蓝牙ble的时候,手机相当于是客户端,需要有一个服务端创建出服务,手机这边才能搜索到蓝牙设备。所以一般都会有两个app,主板app(服务端),手机app(客户端)。这个地方如果不清楚,只在手机app端有安装,是不会搜索ble蓝牙服务的。