有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在没有读取权限的情况下从可扩展客户端读取数据

我目前有一个运行中的Android应用程序(下面是代码片段),可以扫描BLE设备,但只使用硬编码的UUID来处理一个特定的设备。虽然应用程序成功地连接并读取了具有读取权限的数据,但我想要的数据似乎只有NOTIFY and WRITE NO RESPONSE,因此无法正常读取。我正在寻找一个解决办法来绕过这个障碍。我已经试着阅读所有其他服务及其各自的特征,看看我想要的数据是否存在,到目前为止还没有运气

我已扫描该设备以获取其所有服务和特征(提供的所有服务的屏幕截图):

https://imgur.com/a/mYWnAwO

请记住,我知道我正在展示设备的mac地址。然而,知道它是什么类型的设备并不重要

以及组装一个安卓应用程序来读取这些服务的信息。目前,我已经硬编码了UUID,并将其连接到一个可读的服务/特性,但是它的值总是0100(显然不是我想要的)

    public void readCustomCharacteristic() {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }
        /*check if the service is available on the device*/
        BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000feba-0000-1000-8000-00805f9b34fb"));
        if(mCustomService == null){
            Log.w(TAG, "Custom BLE Service not found");
            return;
        }
        /*get the read characteristic from the service*/
        BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fa12-0000-1000-8000-00805f9b34fb"));
        if(mBluetoothGatt.readCharacteristic(mReadCharacteristic) == false){
            Log.w(TAG, "Failed to read characteristic");
        }
    }

    public void writeCustomCharacteristic(int value) {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }
        /*check if the service is available on the device*/
        BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000feba-0000-1000-8000-00805f9b34fb"));
        if(mCustomService == null){
            Log.w(TAG, "Custom BLE Service not found");
            return;
        }
        /*get the read characteristic from the service*/
        BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fa11-0000-1000-8000-00805f9b34fb"));
        mWriteCharacteristic.setValue(value,安卓.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
        if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
            Log.w(TAG, "Failed to write characteristic");
        }
    }

出现在我的服务器(外围设备)上的数字需要是通过BLE捕获的值,并且最确定的是应该在这些服务之一和一个特定特征下。然而,这一切都是找到它并破译它的问题,因此它在我这端(Android应用程序)成为人类可读的


共 (0) 个答案