蓝牙BLE开发基础教程 android5.0 蓝牙4.0 透传 Android Studio(三)

六、收发数据

发送示例

byte[] senddatas =new byte[]{1,2,3,4,34,56,78,90};
bluetoothGattCharacteristic.setValue(senddatas);
bluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic);

接收示例

//在onCharacteristicChanged()中加入以下处理代码
{
    byte[] bytesreceive = characteristic.getValue();
    Log.e(TAG,bytesreceive[0]+""+bytesreceive[1]+""+bytesreceive[2]+""+bytesreceive[4])
}

下面附上制作完成的Android项目文件
蓝牙BLE开发基础教程 android5.0 蓝牙4.0 透传 Android Studio(三)_第1张图片
蓝牙BLE开发基础教程 android5.0 蓝牙4.0 透传 Android Studio(三)_第2张图片

点击这里下载 http://download.csdn.net/detail/deweikaiwen/9808901

你可能感兴趣的:(ble-4-0)