即时警报服务警报级别规范

时间:2013-12-22 20:30:13

标签: android

我正在开发一个连接到CC2541的Android应用程序。我能够看到这些服务的所有服务和特征。我想使用立即警报服务的警报级别特征。我的应用的最后一步是当我点击警报级别charc时。 蜂鸣器响起,但我无法做到这一点。这是我的代码:

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) 
{
    if (mBluetoothAdapter == null || mBluetoothGatt == null) 
    {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    // This is specific to Alert Level.
    if (UUID_ALERT_LEVEL.equals(characteristic.getUuid())) 
    {
        characteristic.setValue("0x0028".getBytes());
        mBluetoothGatt.writeCharacteristic(characteristic);
      /*  BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);*/
    }
}

我不确定使用writeCharacteristic()或writeDescriptior()来实现这一点。我将不胜感激。

http://imgur.com/OEs2s8z

1 个答案:

答案 0 :(得分:0)

我已尝试使用CC2541,当我拨打writeAlertLevel并将其alert level时,蜂鸣器会发出蜂鸣声。

例如,alert levelALERT_HIGH

private static final int ALERT_HIGH = 2;
private static final UUID IMMEDIATE_ALERT_UUID = UUID.fromString("00001802-0000-1000-8000-00805f9b34fb");
private static final UUID ALERT_LEVEL_UUID = UUID.fromString("00002a06-0000-1000-8000-00805f9b34fb");

public void writeAlertLevel(int level) {
BluetoothGattService alertService = mBluetoothGatt.getService(IMMEDIATE_ALERT_UUID);
if(alertService == null) {
Log.d(TAG, "Immediate Alert service not found!");
return;
}
BluetoothGattCharacteristic alertLevel = alertService.getCharacteristic(ALERT_LEVEL_UUID);
if(alertLevel == null) {
Log.d(TAG, "Alert Level charateristic not found!");
return;
}
alertLevel.setValue(level, BluetoothGattCharacteristic.FORMAT_UINT8, 0);
mBluetoothGatt.writeCharacteristic(alertLevel);
}
相关问题