如何接收低功耗蓝牙消息



private BluetoothGattCharacteristic mNotifyCharacteristic;


BluetoothGattService service = gatt.getService(UUID.fromString(serviceUuid));
                mNotifyCharacteristic = service.getCharacteristic(UUID.fromString(characterUuid));

                if (mNotifyCharacteristic != null)
                {
                    //使能Notify
                    setCharacteristicNotification(mNotifyCharacteristic, true);
                }



public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
            boolean enabled)
    {
        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        // This is specific to BLE SPP Notify.
        // if (characterUuid.equals(characteristic.getUuid()))
        {
            BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                    UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mBluetoothGatt.writeDescriptor(descriptor);
        }
    }

1、连接成功后

2、onServicesDiscovered回调中发现服务后,调用setCharacteristicNotification

3、接收通知是在onCharacteristicChanged

上一篇:JS生成uuid的四种方法


下一篇:JavaWeb 案例9 — 表单重复提交问题