2013-12-22 32 views
0

我正在開發連接到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

回答

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