简体   繁体   English

Android设备作为BLE中央和读/写操作,无需外围设备触发

[英]Android device as BLE central and read/write operations without any trigger from peripheral

My Android app is made as a BLE central device. 我的Android应用是作为BLE中央设备制成的。 I have a device which is peripheral. 我有一个外围设备。 I want to send some data from Android app to peripheral device without any request from the peripheral. 我想将一些数据从Android应用发送到外围设备,而无需外围设备的任何请求。 Can I achieve this ? 我能做到吗?

In my peripheral device to write data i am using below code : 在我写数据的外围设备中,我使用以下代码:

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);

Do I have to do in the same way for central also? 我是否也必须以同样的方式来做中央? Any reference links would be helpful. 任何参考链接都将有所帮助。

I think the process is same, you have to write data to the particular characteristic and service. 我认为过程是相同的,您必须将数据写入特定的特性和服务。 You should know the value of the characteristic and service. 您应该知道特性和服务的价值。 In your case it is SampleGattAttributes.LOCAL_TIME . 您的情况是SampleGattAttributes.LOCAL_TIME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 移动/设备同时作为 BLE GATT 外围设备和中央设备 - Android Mobile/Device as a BLE GATT Peripheral & Central Simultaneously 如果其他任何尝试连接的应用程序需要断开连接,我们如何才能使BLE外围设备仅连接到我们的Android应用程序(中央) - How we can achieve the BLE peripheral device to connect to only our Android app (Central) if any other app try to connect need to disconnect 在不使用应用程序的情况下将 Android 设备与 BLE 外设连接 - Connecting an Android Device with a BLE Peripheral without using an App Android Things BLE外设加密的读写权限 - Android Things BLE peripheral encrypted write and read permissions Android:BLE没有“外围”角色吗? - Android: BLE without "peripheral” role? 无法从BLE设备读取,写入正常(Android) - Unable to Read from BLE Device, Write is working (Android) 如何在Android中不配对的情况下从蓝牙BLE设备读取数据 - How to read data from a Bluethooth BLE device without pair in Android Android BLE外围设备数据接收 - Android BLE peripheral device data receiving Android 设备作为 BLE 外设和 GATT 客户端 - Android Device as BLE peripheral and GATT client BLE Peripheral的广告能否唤醒并触发与Android Master设备的连接? - Can BLE Peripheral's advertisements wake up and trigger connection to Master Android device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM