本文整理汇总了Java中android.bluetooth.BluetoothGatt.readDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGatt.readDescriptor方法的具体用法?Java BluetoothGatt.readDescriptor怎么用?Java BluetoothGatt.readDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothGatt
的用法示例。
在下文中一共展示了BluetoothGatt.readDescriptor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isServiceChangedCCCDEnabled
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
* Reads the value of the Service Changed Client Characteristic Configuration descriptor (CCCD).
*
* @param gatt the GATT device
* @param characteristic the Service Changed characteristic
* @return <code>true</code> if Service Changed CCCD is enabled ans set to INDICATE
* @throws DeviceDisconnectedException
* @throws DfuException
* @throws UploadAbortedException
*/
private boolean isServiceChangedCCCDEnabled(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) throws DeviceDisconnectedException, DfuException, UploadAbortedException {
if (mConnectionState != STATE_CONNECTED_AND_READY)
throw new DeviceDisconnectedException("Unable to read Service Changed CCCD", mConnectionState);
// If the Service Changed characteristic or the CCCD is not available we return false.
if (characteristic == null)
return false;
final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
if (descriptor == null)
return false;
mRequestCompleted = false;
mError = 0;
logi("Reading Service Changed CCCD value...");
sendLogBroadcast(LOG_LEVEL_VERBOSE, "Reading Service Changed CCCD value...");
gatt.readDescriptor(descriptor);
// We have to wait until device receives a response or an error occur
try {
synchronized (mLock) {
while ((!mRequestCompleted && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
mLock.wait();
}
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mAborted)
throw new UploadAbortedException();
if (mError != 0)
throw new DfuException("Unable to read Service Changed CCCD", mError);
if (mConnectionState != STATE_CONNECTED_AND_READY)
throw new DeviceDisconnectedException("Unable to read Service Changed CCCD", mConnectionState);
return mServiceChangedIndicationsEnabled;
}