文档详情

android开发环境设置和BLE驱动开发说明教程.pptx

发布:2017-04-30约1.24千字共11页下载文档
文本预览下载声明
Android开发环境设置和Blooth low energy(BLE)驱动开发说明;Android开发环境设置;BLE驱动开发说明;BLE代码说明;;;;四、调用蓝牙适配器的扫描设备函数,寻找设备。 mBluetoothAdapter.startLeScan(mLeScanCallback); // Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(final BluetoothDevice device, int rssi, byte[]scanRecord) { runOnUiThread(new Runnable() { @Override public void run() { mLeDeviceListAdapter.addDevice(device); mLeDeviceListAdapter.notifyDataSetChanged(); } }); } }; 寻找设备一段时间后,记得调用mBluetoothAdapter.stopLeScan(mLeScanCallback);;四、通过扫描得到的地址寻找设备,然后调用设备的connectGatt与设备进行连接,代码如下: Final BluetoothDevice device=mBluetooth.getRemoteDevice(address); Device.connectGatt(this,false,mGattCallback); mGattCallback的类型为BluetoothGattCallback,该类型处理GATT的各种事件,如设备连接完毕或断开;;六、可以调用类BluetoothGattService中的方法来得到设备相关的服务信息,如:getUuid()可以用来得到服务的UUID, getCharacteristics()来得到相关的特性,也可调用类BluetoothGattCharacteristic中的方法getUuid()来获得相关特性的UUID。代码如下: Uuid=gattService.getUuid(); ListBluetoothGattCharacteristic gattCharacteristic=gattService.getCharacteristic();
显示全部
相似文档