![](/img/trans.png)
[英]Android Mobile/Device as a BLE GATT Peripheral & Central Simultaneously
[英]Android device as BLE central and read/write operations without any trigger from peripheral
我的Android應用是作為BLE中央設備制成的。 我有一個外圍設備。 我想將一些數據從Android應用發送到外圍設備,而無需外圍設備的任何請求。 我能做到嗎?
在我寫數據的外圍設備中,我使用以下代碼:
BluetoothGattCharacteristic charac = Service
.getCharacteristic(UUID.fromString(SampleGattAttributes.LOCAL_TIME));
byte[] value = new byte[1];
String valuetosend = "data from client to server";
value = valuetosend.getBytes();
charac.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
charac.setValue(value);
Log.d("BluetoothLeservice::","Write Status:" + charac.getValue());
boolean status = mBluetoothGatt.writeCharacteristic(charac);
我是否也必須以同樣的方式來做中央? 任何參考鏈接都將有所幫助。
我認為過程是相同的,您必須將數據寫入特定的特性和服務。 您應該知道特性和服務的價值。 您的情況是SampleGattAttributes.LOCAL_TIME
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.