(java,bluetooth-lowenergy,ble)如何通过BLE从android设备获取数据

时间:2019-07-01 07:09:34

标签: java bluetooth-lowenergy

https://github.com/android/camera/issues

我是BLE(Bluetooth-LowEnergy)的初学者。我想通过BLE从Android设备获取数据。

我已经阅读了Google文档中的特征。 而且我也已经在Google上搜索过。

我的设备没有响应我的请求字节码。 我认为这是因为我设置了错误的特征。 cus,我认为我对特征并不完全了解。

请问有人帮我设置正确的特征吗?

这是自定义的Uuid(最好在顶部看到添加的图像。)

function uploadFiles() {
var xhr = new XMLHttpRequest();
var file = document.getElementById('upload').files[0];
var formData = new FormData();

formData.append('UploadFiles', file); 
xhr.open('POST', 'https://localhost:44310/api/values/save', true);

new Promise(function (resolve, reject) {
    resolve();
}).then(function () { 
    xhr.setRequestHeader('custom', 'new');
    xhr.send(formData); // Changed position from original code

});
xhr.onerror = function (args) {
    console.log('error occurs..!');
}
}

这是我设置的Uuid

CUSTOM SERVICE
0783b03e-8535-b5a0-7140-a304d2495cb7

NOTIFY Uuid : 0783B03E-8535-B5A0-7140-A304D2495CB8
Read Uuid : 00002a19-0000-1000-8000-00805f9b34fb
Write Uuid : 0783b03e-8535-b5a0-7140-a304d2495cba

这是我的代码

    public final UUID serviceUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d2495cb7");
    public final UUID notifyUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d2495cb8");
    public final UUID readUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    public final UUID writeUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d2495cba");
BluetoothHandler.java
 targetGattCharacteristic = targetGattService.getCharacteristic(Define.GetInstance().notifyUuid);
        BluetoothGattCharacteristic readGattCharacteristic = targetGattService.getCharacteristic(Define.GetInstance().notifyUuid);

        if (readGattCharacteristic != null) {
            mBleService.setCharacteristicNotification(readGattCharacteristic, true);

        } else {
            callInterface();
            return;
        }
(BluetoothService.java)

1 个答案:

答案 0 :(得分:0)