-3

我目前正在开发 android 应用程序,我想将 BLE 应用程序添加到我的应用程序中,也就是说,我想将数据发送到 nrf51822/8001。

请给我一个简单的例子。

谢谢你。

4

1 回答 1

0

你可以在这里找到官方教程:http: //developer.android.com/guide/topics/connectivity/bluetooth-le.html 它将解释你需要知道的一切(扫描、连接和读/写..)

首先你需要一个 BluetoothAdapter:final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter();

要让设备围绕您,您必须执行扫描(当您找到设备时不要忘记停止它,因为它会占用大量资源) mBluetoothAdapter.startLeScan(mLeScanCallback);

要进行连接,请使用 connectGatt(context, boolean connection auto,BluetoothGattCallback mGattCallback) mBluetoothGatt = device.connectGatt(this, false, mGattCallback);

在教程中,当有新设备、新连接或读/写时,他们使用服务来获取更新。

您可以在这里 ddl 项目: https ://android.googlesource.com/platform/development/+/cefd49aae65dc85161d08419494071d74ffb982f/samples/BluetoothLeGatt

对于读写,请检查服务、特性和 UUID

于 2016-03-03T09:06:20.033 回答