BleManager.java 文件源码

java
阅读 38 收藏 0 点赞 0 评论 0

项目:Android-DFU-App 作者:
/**
 * When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic.
 * In case one of the requirements is not fulfilled this method returns <code>false</code>.
 *
 * @param gatt the gatt device with services discovered
 * @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have
 * the Service Changed characteristic or this characteristic does not have the CCCD.
 */
private boolean ensureServiceChangedEnabled(final BluetoothGatt gatt) {
    if (gatt == null)
        return false;

    // The Service Changed indications have sense only on bonded devices
    final BluetoothDevice device = gatt.getDevice();
    if (device.getBondState() != BluetoothDevice.BOND_BONDED)
        return false;

    final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE);
    if (gaService == null)
        return false;

    final BluetoothGattCharacteristic scCharacteristic = gaService.getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC);
    if (scCharacteristic == null)
        return false;

    return enableIndications(scCharacteristic);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号